Is there a way to convert a multidimensional array
to a stdClass
object in PHP?
Casting as (object)
doesn\'t seem to work recu
You can use the array_map
recursively:
public static function _arrayToObject($array) {
return is_array($array) ? (object) array_map([__CLASS__, __METHOD__], $array) : $array;
}
Works perfect for me since it doesn't cast for example Carbon objects to a basic stdClass (which the json encode/decode does)