3 回答

TA贡献1789条经验 获得超8个赞
很简单,首先将您的对象转换为json对象,这会将您的对象字符串转换为JSON代表。
获取该结果并使用额外的参数true解码,它将转换为关联数组
$array = json_decode(json_encode($oObject),true);

TA贡献1796条经验 获得超4个赞
尝试这个:
$new_array = objectToArray($yourObject);
function objectToArray($d)
{
if (is_object($d)) {
// Gets the properties of the given object
// with get_object_vars function
$d = get_object_vars($d);
}
if (is_array($d)) {
/*
* Return array converted to object
* Using __FUNCTION__ (Magic constant)
* for recursive call
*/
return array_map(__FUNCTION__, $d);
} else {
// Return array
return $d;
}
}
- 3 回答
- 0 关注
- 563 浏览
添加回答
举报