PHP print_r() Function
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:
- $expression: the variable to print. If a string, integer or float variable is given, the variable value itself is printed. If an array is given, the keys and elements are displayed in a certain format. An object is similar to an array.
- $return: optional; if true, the result is not output but assigned to a variable instead, while false outputs the result directly.
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.
Available PHP Functions