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
Miguel Nunez3,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?
Jonathan GrieveTreehouse 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.
<pre> <?php $a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z')); print_r ($a); ?> </pre>
You can read more in the above link about what kinds of information you can retrieve from variables.