开发者

How do I generate an Array string from an array in memory (php)

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 th开发者_如何学运维e 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?


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',
  ),
)


Check out var_dump or print_r.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜