php - The most convenient or best way to convert objects to arrays
怪我咯
怪我咯 2017-06-05 11:08:09
0
2
512

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,
}]
怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(2)
習慣沉默

I think the original data is json, so

$data = json_decode($data, true);
$data = array_values($data);
$data = json_encode($data);
小葫芦

A very stupid method (array)$data, this actually works too

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template