var_dump
and print_r
, but they do not store in string , they already give echo
.
What function to use?
var_dump
and print_r
, but they do not store in string , they already give echo
.
What function to use?
The correct function is print_r()
because it accepts a second parameter to pass the output rather than the dump of it:
Example:
$b = array ('m' => 'monkey', 'foo' => 'bar', 'x' => array ('x', 'y', 'z'));
$results = print_r($b, true);
Output to variable $results
:
Array
(
[m] => monkey
[foo] => bar
[x] => Array
(
[0] => x
[1] => y
[2] => z
)
)
The variable $results
will become a string with the above content displayed.
See example on Ideone .
You can use $string = var_export($array, true);
to save an array string