PHP把对象转换成数组 50
[entities]=>Array([0]=>stdClassObject([uuid]=>bfad2f4a-7954-11e5-b4ff-65f091f822e8[ty...
[entities] => Array
(
[0] => stdClass Object
(
[uuid] => bfad2f4a-7954-11e5-b4ff-65f091f822e8
[type] => chatmessage
[created] => 1445584060468
[modified] => 1445584060468
[timestamp] => 1445584059837
[from] => xtmtd
[msg_id] => 120341804573786540
[to] => 1445584043036
[groupId] => 1445584043036
[chat_type] => groupchat
[payload] => stdClass Object
(
[bodies] => Array
(
[0] => stdClass Object
(
[type] => txt
[msg] => ttttt
)
)
)
)
已解决:
function object_to_array($obj){
$_arr = is_object($obj) ? get_object_vars($obj) :$obj;
foreach ($_arr as $key=>$val){
$val = (is_array($val) || is_object($val)) ? $this->object_to_array($val):$val;
$arr[$key] = $val;
}
return $arr;
} 展开
(
[0] => stdClass Object
(
[uuid] => bfad2f4a-7954-11e5-b4ff-65f091f822e8
[type] => chatmessage
[created] => 1445584060468
[modified] => 1445584060468
[timestamp] => 1445584059837
[from] => xtmtd
[msg_id] => 120341804573786540
[to] => 1445584043036
[groupId] => 1445584043036
[chat_type] => groupchat
[payload] => stdClass Object
(
[bodies] => Array
(
[0] => stdClass Object
(
[type] => txt
[msg] => ttttt
)
)
)
)
已解决:
function object_to_array($obj){
$_arr = is_object($obj) ? get_object_vars($obj) :$obj;
foreach ($_arr as $key=>$val){
$val = (is_array($val) || is_object($val)) ? $this->object_to_array($val):$val;
$arr[$key] = $val;
}
return $arr;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询