使用键等于值的键和值获取整个数组

时间:2017-05-12 22:05:39

标签: php arrays json

我的JSON中有数组,如下所示:

[
    {
        "id":"bobbys_burgers",
        "is_enabled":true,
        "name":"Bobbys Burgers",
        "supported_transactions":[
            "222",
            "111",
            "333"
        ],
        "enrollment_required":[
        ],
        "restricted_transactions":[
            "123"
        ]
    },

    {
        "id":"randys_sandwich",
        "is_enabled":true,
        "name":"Randys Sandwich",
        "supported_transactions":[
            "321"
        ],
        "enrollment_required":[
        ],
        "restricted_transactions":[
        ]
    },
]

我希望得到整个数组的所有键id = randys_sandwich。例如,我想搜索id == randys_sandwich并返回is_enablednamesupported_transactions等来自该数组的值。我怎么能在PHP中做到这一点?

1 个答案:

答案 0 :(得分:-1)

你需要对你的数组进行json_decode然后循环遍历数组中的对象,找到你正在寻找的id。

RecyclerView