Easy Tutorial
❮ Func Misc Connection Timeout Func Curl_Multi_Strerror ❯

PHP print_r() Function

Available PHP Functions

The print_r() function is used to print a variable in a more human-readable format.

PHP Version Requirements: PHP 4, PHP 5, PHP 7

Syntax

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

Parameter Description:

Return Value

If $return is set to true, it returns a human-readable string.

Example

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

Output:

Array
(
    [a] => apple
    [b] => banana
    [c] => Array
        (
            [0] => x
            [1] => y
            [2] => z
        )

)

Setting the $return parameter:

<?php
$b = array ('m' => 'monkey', 'foo' => 'bar', 'x' => array ('x', 'y', 'z'));
$results = print_r ($b, true); // $results contains the output of print_r
?>

The above information does not output the result because the output is assigned to the $results variable.

Available PHP Functions

❮ Func Misc Connection Timeout Func Curl_Multi_Strerror ❯