Abadis
Abadis

Reputation: 2821

Function like var_dump in php

I need a function like var_dump($object) in php The problem is that the Var_dump function print every thing on the screen and I just need the answer in a variable. I mean sth like $variable=var_dump($object); And I dont want to see anything on screen! thanks

Upvotes: 3

Views: 2107

Answers (4)

tim
tim

Reputation: 2722

Sometimes json_encode() can be handy:

$variable = json_export($data);

Or

$variable = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);

Upvotes: 0

Shakti Singh
Shakti Singh

Reputation: 86406

$variable=var_export($object,true);

you needs var_export

Upvotes: 5

Ziumin
Ziumin

Reputation: 4860

U can also use the output-control functions

ob_start();
var_dump($object);
$description = ob_get_clean();

Upvotes: 2

Piotr Olaszewski
Piotr Olaszewski

Reputation: 6204

Maybe you use:

$variable = print_r($object, true);

Upvotes: 5

Related Questions