PHP print_r() Function
print_r()The function is used to print a variable in a more readable form.
PHP Version Requirements: PHP 4, PHP 5, PHP 7
Syntax
bool print_r ( mixed $expression [, bool $return ] )
Parameter Description:
- $expression: The variable to be printed. If it is a string, integer, or float type variable, the variable value itself will be printed. If it is an array, the keys and elements will be displayed in a certain format. Objects are similar to arrays.
- $return: Optional. If true, the result is not output, but assigned to a variable; if false, the result is output directly.
Return Value
$returnIf set totrueThere is a return value, which is an easy-to-understand string message.
Example
Example
$a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x','y','z'));
print_r ($a);
The output result is:
Array
(
[a] => apple
[b] => banana
[c] => Array
(
[0] => x
[1] => y
[2] => z
)
)
Set$returnParameter:
Example
$b = array ('m' => 'monkey', 'foo' => 'bar', 'x' => array ('x', 'y', 'z'));
$results = print_r ($b, true); //$results contains the output result of print_r
The above information has no output because the output result was assigned to$resultsvariable.
Other Extensions
PHP Available Functions