...Beauty, cleaning, DIY tips and more - free to join!
   Login   Contact us   Site map   Puzzle Club   Ask a question    Newsletter

How To View Array Contents In PHP

Computing : Learning PHP

Often when debugging a PHP program it is useful to insert frequent echo statements (or print) to see what is going on.

However with arrays it can be harder to get at the contents, without using a list or while or for loop or other way of iterating through.

Just to see a dump however the easiest way by far is to use the print_r command with takes the array as the argument, thus:

print_r($myarray); will show like this 0--> hello, 1 --> fred and so forth.

Note to view it in a more print friendly format place HTML pre tags around the print_r.


Profile image!
By: Stephen

  Reply to How To View Array Contents In PHP

  Receive Our Newsletter

learn PHP picture



Questions about learn PHP:

Ask question

More Articles:
How to install PHP on home computer
How to get an autoresponder
How to make your website more accessible