I need to create a big array in my code, I have the values in several tables (for easy management). I select it and now I have all the values in an array, in memory in the way I want. My problem, I need to write this array down, into the code. Is there a way to take an array which sits in the memory and translate it into a string "array('g'=>'h','b'=>'d'....)" which I can then echo and just copy-paste into my code?
+6
A:
You want the var_export()
function. From the manual:
<?php
$a = array (1, 2, array ("a", "b", "c"));
var_export($a);
?>
The above example will output:
array (
0 => 1,
1 => 2,
2 =>
array (
0 => 'a',
1 => 'b',
2 => 'c',
),
)
Andy
2010-03-19 21:37:47
var_export is a quick debugging gem along with it's second argument
ChrisR
2010-03-19 21:43:27
both `var_dump` and `print_r` do not output valid php - they are purely for debugging
Cal
2010-03-20 01:32:20