Printing the contents of a PHP Array

This is a pretty common task, but it’s surprising how many PHP newbies don’t know about it yet. If you want to see the structure of your PHP Array, all you need to do is this:

 

print_r($myarray);

This will give you a listing of all the items in the array, including multi-dimensional arrays. Obviously this should only be used for testing / debugging purposes.

Lowell Heddings is the founder and Editor-in-Chief of How-To Geek. He spends all his free time making sure this site can bring you fresh geekery on a daily basis, and has been doing so for over eleven years.