What is the convenient way to convert objects to arrays
Original data
$data = {
"1": {
"id": 1,
"name": "超市类",
"pid": 0,
},
"3": {
"id": 3,
"name": "餐饮类",
"pid": 0,
},
"4": {
"id": 4,
"name": "造型类",
"pid": 0,
},
}
Target Result
$data = [{
"id": 1,
"name": "超市类",
"pid": 0,
},{
"id": 3,
"name": "餐饮类",
"pid": 0,
},{
"id": 4,
"name": "造型类",
"pid": 0,
}]
習慣沉默2017-06-05 11:10:09
I think the original data is json, so
$data = json_decode($data, true);
$data = array_values($data);
$data = json_encode($data);