print_r
Description
The print_r of Variable Handling for PHP prints human-readable information about a variable.
Syntax
print_r( mixed $value, bool $return = false ): string|true
Parameters
value
The expression to be printed.
return
If you would like to capture the output of print_r(), use the return parameter. When this parameter is set to true, print_r() will return the information rather than print it.
Return
If given a string, int or float, the value itself will be printed. If given an array, values will be presented in a format that shows keys and elements. Similar notation is used for objects.
When the return parameter is true, this function will return a string. Otherwise, the return value is true.
Examples
1 · value · bool
<? $value = false; print_r($value);
2 · value · int
<? $value = 0; print_r($value);
0
3 · value · float
<? $value = 0.0; print_r($value);
0
4 · value · string
<? $value = "0"; print_r($value);
0
5 · value · array
<? $value = [0]; print_r($value);
Array ( [0] => 0 )
6 · value · object · standard class
<? $value = new stdclass; $value->var = 0; print_r($value);
stdClass Object ( [var] => 0 )
7 · value · object · custom class
<? class myclass { public $var; } $value = new myclass; $value->var = 0; print_r($value);
myclass Object ( [var] => 0 )
8 · return · false
<? $value = 0; $return = false; $output = print_r($value, $return); echo PHP_EOL . "output: "; var_dump($output);
0 output: bool(true)
9 · return · true
<? $value = 0; $return = true; $output = print_r($value, $return); echo PHP_EOL . "output: "; var_dump($output);
output: string(1) "0"
Links
Related
Variable Handling
- boolval
- debug_zval_dump
- doubleval
- empty
- floatval
- get_debug_type
- get_defined_vars
- get_resource_id
- get_resource_type
- gettype
- intval
- is_array
- is_bool
- is_callable
- is_countable
- is_double
- is_float
- is_int
- is_integer
- is_iterable
- is_long
- is_null
- is_numeric
- is_object
- is_real
- is_resource
- is_scalar
- is_string
- isset
- serialize
- settype
- strval
- unserialize
- unset
- var_dump
- var_export