Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP PHP Functions Function Returns and More Returning Values

Miguel Nunez
Miguel Nunez
3,266 Points

What is it meant when coders say this about print_r in php?

The print_r() function is used to print human-readable information about a variable. What is this ment when they say that and why do we use this if we can just use print or echo instead? What situations is this needed in?

1 Answer

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,250 Points

print_r is a bit like var_dump() in which it will display certain properties of a variable.

You can use it to print out the list of keys in and their values in an array for example.

$a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z'));
print_r ($a);


You can read more in the above link about what kinds of information you can retrieve from variables.

Miguel Nunez
Miguel Nunez
3,266 Points

So its like var_dump for arrays?