PHP - recursive Array to Object?

前端 未结 14 1262
夕颜
夕颜 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:56

    Late, but just wanted to mention that you can use the JSON encoding/decoding to convert fully from/to array:

    //convert object $object into array
    $array = json_decode(json_encode($object), true);
    //convert array $array into object
    $object = json_decode(json_encode($array));
    

    json_encode and json_decode functions are available starting from php 5.2

提交回复
热议问题