我有这个数组:
$items_pool = Array (
[0] => Array ( [id] => 1 [quantity] => 1 )
[1] => Array ( [id] => 2 [quantity] => 1 )
[2] => Array ( [id] => 72 [quantity] => 6 )
[3] => Array ( [id] => 4 [quantity] => 1 )
[4] => Array ( [id] => 5 [quantity] => 1 )
[5] => Array ( [id] => 7 [quantity] => 1 )
[6] => Array ( [id] => 8 [quantity] => 1 )
[7] => Array ( [id] => 9 [quantity] => 1 )
[8] => Array ( [id] => 19 [quantity] => 1 )
[9] => Array ( [id] => 20 [quantity] => 1 )
[10] => Array ( [id] => 22 [quantity] => 1 )
[11] => Array ( [id] => 29 [quantity] => 0 )
)
我正在尝试遍历此数组并根据$items_pool[][id]
的值执行条件。我想报告回TRUE或NULL / FALSE,所以我只是测试存在是否具体。
答案 0 :(得分:2)
这样的事情:
$items_pool = array(...);
$result = false;
foreach ($items_pool as $item) {
if ('something' == $item['id']) {
$result = true;
break;
}
}
答案 1 :(得分:1)
循环检查是否有空......
foreach($items_pool as $arr){
echo $arr['id'].'==>'.$arr['quantity'];
if($arr['quantity'] == 0){
echo 'id:'.$arr['id'].' is empty!';
return false;
}
}