stdClass to array?

后端 未结 11 1758
情话喂你
情话喂你 2020-12-03 05:05

i have:

stdClass Object
(
    [0] => stdClass Object
        (
            [one] => aaa
            [two] => sss
        )

    [1] => stdClass O         


        
11条回答
  •  有刺的猬
    2020-12-03 05:33

    Your problem is probably solved since asking, but for reference, quick uncle-google answer:

    function objectToArray($d) {
      if(is_object($d)) {
        $d = get_object_vars($d);
      }
      if(is_array($d)) {
        return array_map(__FUNCTION__, $d); // recursive
      } else {
        return $d;
      }
    }
    

    Full article here. Note I'm not associated with the original author in any way.

提交回复
热议问题