tags:

views:

294

answers:

6

The title should be clear.

+1  A: 

You can't. var_dump just outputs text but doesn't return anything.

Joey
A: 

var_dump(array($var)) ?

Fragsworth
+6  A: 

Use var_export if you want a representation which is also valid PHP code

$a = array (1, 2, array ("a", "b", "c"));
$dump=var_export($a, true);
echo $dump;

will display

array (
 0 => 1,
 1 => 2,
 2 => 
 array (
   0 => 'a',
   1 => 'b',
   2 => 'c',
 ),
)

To turn that back into an array, you can use eval, e.g.

eval("\$foo=$dump;");
var_dump($foo);

Not sure why you would want to do this though. If you want to store a PHP data structure somewhere and then recreate it later, check out serialize() and unserialize() which are more suited to this task.

Paul Dixon
+1  A: 

Maybe you’re looking for var_export that will give you a valid PHP expression of the passed value.

Gumbo
just edited your answer thinking it was mine! sorry!
Paul Dixon
+1  A: 

Perhaps you are trying to convert an object to an array? http://www.phpro.org/examples/Convert-Object-To-Array-With-PHP.html

Palantir
+1  A: 

var_export creates php code, which you could run through eval

but i wonder, what is your idea?

knittl