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! While you're at it, check out some resources Treehouse students have shared here.

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
MOD
Jonathan Grieve
Treehouse Moderator 91,252 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>

http://php.net/manual/en/function.print-r.php

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?