过滤API代码中的数据

时间:2018-10-25 09:37:31

标签: api codeigniter

如何从API数组过滤数据

我已经编写了以下代码以获取API响应

$url = "https://j2wofferletter.com/api/v1/active_employees_info";
$active_employees = file_get_contents($url);
$pos = json_decode($active_employees);

从上面的代码中,我得到的是json响应以下

{
    active_employees: [
        {
            {
                "emp_name": "ABC",
                "client_id": 912,
                "salary"   : 1000, 
                "client_name": "Allstate"
            },
            {
                "emp_name": "bbb",
                "client_id": 912,
                "salary"   : 2000,
                "client_name": "Allstate"
            },
            {
                "emp_name": "ccc",
                "client_id": 912,
                "salary"   : 1000,
                "client_name": "IBM"
            },
            {
                "emp_name": "ddd",
                "client_id": 912,
                "salary"   : 2000,
                "client_name": "IBM"
            },
        }
    ]
}

我如何才能明智地获得所有员工的总和

  Expecting output
     Allstate - 3000(total emp salary)
     Ibm - 3000(total emp salary)

0 个答案:

没有答案