Source Code:
(back to article)
<?php class sample { /* Member variables */ var $var1; var $var2; function __construct($par1, $par2) { $this->var1 = $par1; $this->var2 = $par2; } } // Creating the object $myObj = new sample(1000, "second"); echo "Before conversion: \n"; var_dump($myObj); // Converting object to associative array $myArray = json_decode(json_encode($myObj), true); echo "After conversion: \n"; var_dump($myArray); ?>
Result:
Report an issue