PHP - recursive Array to Object?

前端 未结 14 1268
夕颜
夕颜 2020-12-14 14:10

Is there a way to convert a multidimensional array to a stdClass object in PHP?

Casting as (object) doesn\'t seem to work recu

14条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-14 14:51

    The shortest I could come up with:

    array_walk_recursive($obj, function (&$val) { if (is_object($val)) $val = get_object_vars($val); });
    

提交回复
热议问题