Blog

PHP Snippet – parse_jsonc()

A few months ago I wrote a quick post showing how to parse JSONC (JSON with comments) files in JavaScript. Shortly thereafter I adapted the code to work in PHP as well: This function takes the same arguments that you can pass to the native json_decode() function. Besides removing JavaScript Read more…

By Chris West, ago
Blog

PHP – Problem with issetor()

In case you haven’t seen it before, issetor() is a quick and dirty way of getting a value from a variable that may or may not be defined: One unfortunate side-effect that most people are unaware of is that even though you can use this function without needing to worry Read more…

By Chris West, ago
Blog

PHP – Foreach By Reference

Today I was writing some code in which I wanted to modify the values of an array within a for-loop. The obvious solution would be to use the key to modify the value but there is actually another way of doing it: The above code will actually go through the Read more…

By Chris West, ago
Blog

Here Document

Something that you may not know about PHP and many other languages is that it provides heredoc syntax to build strings. What does this mean? Check out the following: The above puts the following into the $myCode variable as a string: You can use this syntax in many different languages: Read more…

By Chris West, ago