Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP print_r() Function

PHP print_r() Function

PHP Available FunctionsAvailable PHP Functions

print_r() The function is used to print a variable in a more easily understandable form.

PHP version requirement: PHP 4, PHP 5, PHP 7

Syntax



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

Parameter Description:

Return Value

$return if set to true will return a value, which is a human-readable string message.

Example

Example

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

The output is:



Array

(

    [a] => apple

    [b] => banana

    [c] => Array

        (

            [0] => x

            [1] => y

            [2] => z

        )



)

Setting the $return parameter:

Example

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

The above information produces no output because the output is assigned to the $results variable.

PHP Available FunctionsAvailable PHP Functions