2 回答
TA贡献1808条经验 获得超4个赞
虽然这不是 Laravel 和所有这些函数式风格,但至少它只在数组上循环一次:
// Take first element so as to know what keys do we have:
$keys = $items[0];
foreach ($items as $item) {
foreach ($item as $key => $value) {
if ($value === null) {
// unset the key which has NULL value
unset($keys[$key]);
}
// if there no keys left - break all loops
if (empty($keys)) {
break 2;
}
}
}
print_r(array_keys($keys));
还有小提琴。
TA贡献1813条经验 获得超2个赞
对二维数组使用两次 foreach 循环。前任: '''
foreach($array as $k=>$v){
//$k is 0
//$v contains another inside array so use another foreach loop
foreach($v as $x => $y){
if($y != "null" && $x != "null" && $x == "name"){
echo $x; //it contains key ex : name
echo $y; //it contains value ex : 1
$z[$x]=$y; // it contains only name key
}
}
}
'''
- 2 回答
- 0 关注
- 130 浏览
添加回答
举报