Ezhil
Ezhil

Reputation: 389

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:gapiReportEntry: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...

Upvotes: 1

Views: 956

Answers (3)

pb149
pb149

Reputation: 2298

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?

Upvotes: 0

Pelle
Pelle

Reputation: 6578

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().

Upvotes: 0

Shakti Singh
Shakti Singh

Reputation: 86366

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);

Upvotes: 1

Related Questions