Subscribe to How-To Geek

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.

The Geek is the founder of How-To Geek and a geek enthusiast. When he's not coming up with great how-to articles, he's probably writing at his personal blog. This article was written on 09/26/06 and tagged with: Programming, PHP

Comments (6)

  1. sven

    and if you like it human-readable:
    echo ""; print_r($myarray); echo "";

    have fun!

  2. Magic.Crazy

    this is more human-readable :

    echo '';
    print_r($array);
    echo '';

  3. Hmmmm

    You may want to try this:

    echo "";
    print_r($location);
    echo "";

  4. Hmmmm

    echo "(html open tag)pre(html close tag)";
    print_r($location);
    echo "\";

  5. Hmmmm

    echo "(less than sign)pre(greater than sign)";
    print_r($location);
    echo "(less than sign)/pre(greather than sign)";

  6. Hmmmm

    between the quotes are the html pre tags (open and then close).


Leave a Comment




Leave your friendly comment here. If you have a computer help question, leave it on the forums instead.

Note: Your comment may not show up immediately on the site.

Sponsored Links
Getting Started
About How-To Geek
Popular Articles

Copyright © 2006-2008 HowToGeek.com. All Rights Reserved.