The function print_r(), prints information about a variable that is human-readable. This function also shows protected and private properties of objects. Static class members will not be shown.
string|bool print_r ( mixed $value , bool $return = false )
Sr.No | Parameter | Description |
---|---|---|
1 |
value |
Mandatory. The expression to be printed. |
2 |
return |
Optional. When set to true, this function will return the information (not print it). This information can be collected or stored. Default is false |
This function returns type depends on the type of value passed:
PHP 4 and above
Following example demonstrates print_r() use:
<?php $a = array ('t' => 'tutorials', 'p' => 'point', 'c' => array ('a', 'b', 'c')); print_r ($a); ?>
This will produce following result −
Array ( [t] => tutorials [p] => point [c] => Array ( [0] => a [1] => b [2] => c ) )
Following example demonstrates print_r() use with return parameter set to true:
<?php $b = array('1' => 'Pune', '2' => 'Bengaluru', 'x' => array ('x', 'y', 'z')); $results = print_r ($b, true);// $results contains output from print_r var_dump($results); ?>
This will produce following result −
string(148) "Array ( [1] => Pune [2] => Bengaluru [x] => Array ( [0] => x [1] => y [2] => z ) ) "