Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在json响应中选择一个数组_Php_Arrays_Json_Laravel - Fatal编程技术网

Php 在json响应中选择一个数组

Php 在json响应中选择一个数组,php,arrays,json,laravel,Php,Arrays,Json,Laravel,我有一个json响应,如下所示: { "orders": [ { "position": 0, "order": { "link": "saudagar_gadget", "count": 979, } }, { "position": 1, "order":

我有一个json响应,如下所示:

{
    "orders": [
        {
            "position": 0,
            "order": {
                "link": "saudagar_gadget",
                "count": 979,
            }
        },
        {
            "position": 1,
            "order": {
                "link": "admin_wg",
                "count": 289,
            }
        },
        {
            "position": 2,
            "order": {
                "link": "admin.wg_shop",
                "count": 200,
            }
        },
    ],
}
当用户选择链接时,我希望搜索响应中的链接,然后相应地提取所需的顺序,然后显示该顺序的计数


如何进行此搜索?使用哪个
php
函数?

以下是您的操作方法

Route::get({link}',函数(){
$link=request('link');//从请求url获取所需的链接
//将json解码为数组
$array=json_解码('{
“命令”:[
{
“位置”:0,
“命令”:{
“链接”:“saudagar_小工具”,
“计数”:979
}
},
{
"立场":一,,
“命令”:{
“链接”:“管理员工作组”,
“计数”:289
}
},
{
"立场":二,,
“命令”:{
“链接”:“管理工作组商店”,
“计数”:200
}
}
]
}');
//因为我们使用的是Laravel,所以收集数组顺序以公开有用的收集方法
$orders=collect($array->orders);
//通过where子句查询集合,where子句通过请求参数匹配订单的链接
返回$orders->where('order.link',$link)->first()->order->count;//获取第一个结果并通过对象表示法访问其值
});

结果:
200

我收到的
方法get不存在。
路由::get({link}),函数()的错误。这只是一个示例,不要只是复制粘贴所有内容,而是根据代码的其余部分在控制器方法中使用它