How to use PHP print_r() Function

This PHP Tutorial will give you some information about “PHP print_r() function”, which includes Syntax, Examples, Usage and output. The print_r() will print any array including multidimensional Arrays. The return parameter will let you capture the output of print_r(). When this parameter is set to TRUE, print_r() will return the information rather than print it.


mixed print_r ( mixed $expression [, bool $return = false ] )

PHP print_r() Function

 'Certification ',
               'b' => 'Paths', 
               'c' => array ('ccna', 'ccnp', 'ccie'));
print_r ($myar);


    [a] => This php code
    [b] =>  is written by 
    [c] => Array
            [0] => noob
            [1] => prof
            [2] => expert


Return Statement
Or you can use another variable to store output from print_r and later echo it to get the above output again.
$results = print_r($myar, true);
echo $results;

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.