Skip to content

Instantly share code, notes, and snippets.

@moskalukigor
Created November 11, 2016 14:36
Show Gist options
  • Save moskalukigor/ce6ce036c974484f951236067d3fcee9 to your computer and use it in GitHub Desktop.
Save moskalukigor/ce6ce036c974484f951236067d3fcee9 to your computer and use it in GitHub Desktop.
StdClass to Array (arrayCastRecursive)
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