php object转数组示例

原本是这样格式的数据:

object(ThriftServerPageCards)#32 (3) {
  ["cards"]=>
  array(10) {
    [0]=>
    object(ThriftServerCards)#33 (8) {
      ["id"]=>
      int(170)
      ["packageID"]=>
      int(4)
      ["ccID"]=>
      string(19) "898601137211040433n"
      ["telephone"]=>
      string(11) "1452006059n"
      ["batch"]=>
      string(1) "1"
      ["producedAt"]=>
      string(19) "2014-12-31 00:00:00"
      ["development"]=>
      int(0)
      ["status"]=>
      int(1)
    }
}
}

通过这个方法可以转换为php数组形式

function std_class_object_to_array($stdclassobject)
{
    $_array = is_object($stdclassobject) ? get_object_vars($stdclassobject) : $stdclassobject;
    foreach ($_array as $key => $value) {
        $value = (is_array($value) || is_object($value)) ? std_class_object_to_array($value) : $value;
        $array[$key] = $value;
    }
    return $array;
}
原文地址:https://www.cnblogs.com/xiaoyueer/p/4308693.html