How to “echo” an array in PHP

The PHP echo() function is great for spitting out your basic types of values, such as strings and numbers. But if you want to see the values, or even better the data structure, of an array you will need to use a different method. This is where print_r() comes in handy.

The print_r() function prints human-readable or human-friendly information about a variable, not just arrays. For this subject I’ll illustrate some examples using print_r with arrays.