Skip to content

Instantly share code, notes, and snippets.

@cdeocampo
Forked from grimicorn/obj_to_assoc_array.php
Created October 8, 2012 03:15
Show Gist options
  • Select an option

  • Save cdeocampo/3850528 to your computer and use it in GitHub Desktop.

Select an option

Save cdeocampo/3850528 to your computer and use it in GitHub Desktop.

Revisions

  1. @grimicorn grimicorn renamed this gist Jul 8, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. @grimicorn grimicorn created this gist Jun 1, 2012.
    20 changes: 20 additions & 0 deletions gistfile1.aw
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    function objectToArray($d) {
    if (is_object($d)) {
    // Gets the properties of the given object
    // with get_object_vars function
    $d = get_object_vars($d);
    }

    if (is_array($d)) {
    /*
    * Return array converted to object
    * Using __FUNCTION__ (Magic constant)
    * for recursive call
    */
    return array_map(__FUNCTION__, $d);
    }
    else {
    // Return array
    return $d;
    }
    } // objectToArray()