Created
November 11, 2016 14:36
-
-
Save moskalukigor/ce6ce036c974484f951236067d3fcee9 to your computer and use it in GitHub Desktop.
StdClass to Array (arrayCastRecursive)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function arrayCastRecursive($array) | |
{ | |
if (is_array($array)) { | |
foreach ($array as $key => $value) { | |
if (is_array($value)) { | |
$array[$key] = arrayCastRecursive($value); | |
} | |
if ($value instanceof stdClass) { | |
$array[$key] = arrayCastRecursive((array)$value); | |
} | |
} | |
} | |
if ($array instanceof stdClass) { | |
return arrayCastRecursive((array)$array); | |
} | |
return $array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment