我有这个变量$office,它会在 print_r 时输出:
{
"total": 3,
"results": [
{
"id": "4",
"blog_id": "11",
"office_name": "Japan",
"office_status": "inactive"
},
{
"id": "5",
"blog_id": "11",
"office_name": "USA",
"office_status": "active"
},
{
"id": "6",
"blog_id": "11",
"office_name": "London",
"office_status": "inactive"
},
}
}
现在我想创建一个新变量,其中带有office_statusof 的 变量active只会出现,我想要的输出是:
{
"total": 1,
"results": [
{
"id": "5",
"blog_id": "11",
"office_name": "",
"office_status": "active"
},
}
}
这是我到目前为止尝试过的,但它仍然返回所有数组:
$v= "active";
$k = "office_status";
foreach($offices as $k => $v) {
$offices_active[$k] = array_filter($v);
}
print_r($offices_active);
请帮忙。谢谢
MYYA
温温酱