Skip to content

Instantly share code, notes, and snippets.

@eyedroot
Forked from victorbstan/php_object_to_array.php
Created August 27, 2019 04:15
Show Gist options
  • Select an option

  • Save eyedroot/18c222129d3bac86996c2f58c0dc79f0 to your computer and use it in GitHub Desktop.

Select an option

Save eyedroot/18c222129d3bac86996c2f58c0dc79f0 to your computer and use it in GitHub Desktop.

Revisions

  1. @victorbstan victorbstan created this gist Dec 17, 2010.
    10 changes: 10 additions & 0 deletions php_object_to_array.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    <?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);