我有一个包含不同键的数组,我想根据值 TRUE 或 FALSE 过滤键。我有麻烦请帮忙。这是我的代码 foreach ($combine as $data) { unset($data['user_name'], $data['date']); if (array_values($data) == TRUE) { pr(array_keys($data)); } }这是数组 Array ( [microsoft] => FALSE [health_care] => TRUE [nasa_cerification_type_i] => TRUE [nasa_cerification_type_ii] => TRUE [nasa_cerification_type_iii] => TRUE )
2 回答
一只名叫tom的猫
TA贡献1906条经验 获得超3个赞
我认为这就是你想要做的:
foreach($combine as $data){
unset($data['user_name'], $data['date']); //we don't need these
$valid = [];
foreach($data as $n => $v){
if($v === true){ //be careful! Are the values really boolean? then use ===, otherwise use ==
$valid[] = $n;
}
}
//do something with $valid
print_r($valid); //etc..
}
喵喵时光机
TA贡献1846条经验 获得超7个赞
$trueArray=array_filter($array, function ($ar){
return ($ar==true);
});
$falseArray=array_filter($array, function ($ar){
return ($ar==false);
});
print_r($trueArray);
- 2 回答
- 0 关注
- 192 浏览
添加回答
举报
0/150
提交
取消