Use var_export if you want a view that is also valid PHP code
$a = array (1, 2, array ("a", "b", "c"));
$dump=var_export($a, true);
echo $dump;
will display
array (
0 => 1,
1 => 2,
2 =>
array (
0 => 'a',
1 => 'b',
2 => 'c',
),
)
To return this back to an array, you can use eval, for example.
eval("\$foo=$dump;");
var_dump($foo);
Not sure why you would like to do this. If you want to save the PHP data structure somewhere, and then recreate it later, check serialize () and unserialize () , which are more suitable for this task.
source
share