(资料图片)
本教程操作环境:windows10系统、PHP8.1版、DELL G3电脑
说明
例子
$data=$orderList->getCollection()->map(function ($order){ return new OrderResponse($order); }); dd($data->toArray());
登录后复制
返回如下
^ array:8 [ 0 => app\admin\Responses\OrderResponse {#122 +"statistical_date": "2021-09-10" +"order_num": 1 +"play_type_count": 1 +"invalid_order_count": 1 } 1 => app\admin\Responses\OrderResponse {#119 +"statistical_date": "2021-09-09" +"order_num": 6 +"play_type_count": 6 +"invalid_order_count": 3 }]
登录后复制
处理方法
$data=json_decode(json_encode($data),true);
登录后复制
返回如下
array:8 [ 0 => array:4 [ "statistical_date" => "2021-09-10" "order_num" => 1 "play_type_count" => 1 "invalid_order_count" => 1 ] 1 => array:4 [ "statistical_date" => "2021-09-09" "order_num" => 6 "play_type_count" => 6 "invalid_order_count" => 3 ]]
登录后复制
推荐学习:《PHP视频教程》
以上就是php怎么将对象转成数组的详细内容,更多请关注php中文网其它相关文章!