如何在对象数组中获取匹配的对象?

时间:2016-08-05 07:05:59

标签: javascript jquery

这是我的目标。在bun数组中,我有2个对象。我只需要访问"oid": 1"bid": 1对象详细信息。无需访问第二个对象。

{
    "oid": "1",
    "oname": "Fon",
    "bun": [{
        "bid": "1",
        "bname": "Ets",
        "dep": [{
            "did": "1",
            "dname": "Dptment",
            "pids": [{
                "pid": "1",
                "st": "active"
            }, {
                "pid": "2",
                "st": "active"
            }]
        }]
    }, {
        "bid": "2",
        "bname": "US",
        "description": "unit2",
        "dep": []
    }]
}

怎么可能?

1 个答案:

答案 0 :(得分:3)

实现的一种方法是使用过滤器。

$user = DB::connection('mysql')->select('select * from usersdata');

foreach ($user as $record) {
    $user = DB::connection('mysql1')->table("tablename")->insert(get_object_vars($record));