views:

43

answers:

2

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
var_export is a quick debugging gem along with it's second argument
ChrisR
A: 

Check out var_dump or print_r.

Matt Huggins
both `var_dump` and `print_r` do not output valid php - they are purely for debugging
Cal
I misunderstood the question, thanks for pointing that out.
Matt Huggins