telekommander
4/21/2016 - 11:57 AM

recursively cast a PHP object to array

recursively cast a PHP object to array

<?php
/*
This function saved my life.
found on: http://www.sitepoint.com/forums//showthread.php?t=438748
by: crvandyke

It takes an object, and when all else if/else/recursive functions fail to convert the object into an associative array, this one goes for the kill. Who would'a thunk it?!
*/

$array = json_decode(json_encode($object), true);