Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbreuss/b022fb1bfcffbcf6a65f7273b9dab4cc to your computer and use it in GitHub Desktop.
Save tbreuss/b022fb1bfcffbcf6a65f7273b9dab4cc to your computer and use it in GitHub Desktop.
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment