Posted in PHP

Debugging: display the contents of an array

While using PHP it’s hard to keep guessing the contents of any $value that you’re playing about with.
Recently @nielslange showed me how to make this much easer with a simple debug function:

By placing this short snippet (I’d recommend in your functions.php file, then you can later use this debug again) you can then use:

debug($yourValueHere);

on any $value in your PHP to see the contents!

Here’s an example:

Now reloading that PHP file shows the associated values to $images neatly within <pre> tags.
In my case, this showed the contents of $images as:

With the above information we can quickly write out our PHP without relying on guessing. Effective, thanks Niels!

Leave a Reply

Your email address will not be published. Required fields are marked *