...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.


By: Stephen

Share on Facebook: On Twitter: TwitterTweet this!

  Reply to How To View Array Contents In PHP

  Receive Our Newsletter




Questions about learn PHP:

Ask question

More Articles:
How to restrict search results to UK sites
How to turn 'lurkers' into 'posters'
How to test different approaches