2 回答

TA貢獻(xiàn)1808條經(jīng)驗(yàn) 獲得超4個(gè)贊
雖然這不是 Laravel 和所有這些函數(shù)式風(fēng)格,但至少它只在數(shù)組上循環(huán)一次:
// 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貢獻(xiàn)1813條經(jīng)驗(yàn) 獲得超2個(gè)贊
對(duì)二維數(shù)組使用兩次 foreach 循環(huán)。前任: '''
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 關(guān)注
- 184 瀏覽
添加回答
舉報(bào)