开发者

how to create an array from var_dump() result

I var_dump and array and got a value printed, how do i create an array from the result. the array is generated a method and i clearly dont know the structure of the array.

Array ( [0] => gapiReportEntry Object ( [metrics:g开发者_如何学GoapiReportEntry:private] => Array ( [visits] => 4 ) [dimensions:gapiReportEntry:private] => Array ( [year] => 2011 [month] => 07 [day] => 20 ) ) [1] => gapiReportEntry Object ( [metrics:gapiReportEntry:private] => Array ( [visits] => 32 ) [dimensions:gapiReportEntry:private] => Array ( [year] => 2011 [month] => 07 [day] => 13 ) ))

the above is the var_dump result.

I tried to recreate it

$nuarr = array(); $nuarr[0] = array("metrics:gapiReportEntry:private"=>array("visits"=>4),"dimensions:gapiReportEntry:private"=>array("year"=>2011,"months"=>07,"day"=>20)); $nuarr[1] = array("metrics:gapiReportEntry:private"=>array("visits"=>10),"dimensions:gapiReportEntry:private"=>array("year"=>2011,"months"=>07,"day"=>10));

but it doesn't return the same var_dunp value.

Could anyone structure the array for me...


Just assign the new array using assignment operator =

$nuarr = $first_array;

Now the $nuarr is an identical copy of your $first_array.

You can also use the var_export

$nuarr = var_export($first_array, true);


You don't mention why you want to do this. If what you need is just an array-to-string and vice versa mechanism, consider using serialize() and unserialize() rather than var_dump().


If you want to print out an array so that you can clearly see its structure, couldn't you do the following?

echo '<pre>'.print_r($array,1)',</pre>';

I know it isn't using var_dump(), but it would produce the desired result, wouldn't it?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜