我有一个这样的数组:
Array
(
[0] => Array
(
[score] => 80
[seen] => 1
)
[1] => Array
(
[score] => 4
[seen] => 1
)
[2] => Array
(
[score] => 4
[seen] => 0
)
[3] => Array
(
[score] => 4
[seen] => 0
)
[4] => Array
(
[score] => 4
[seen] => 0
)
)
我需要检查是否有[seen] = 1
?
if ( /* ??? */ ){
echo "Yes, at least one of [seen] keys is 1";
} else {
echo "No, all [seen] keys are 0";
}
我该如何创造这种条件?
答案 0 :(得分:0)
使用简单的foreach
循环可以帮助您
foreach ($array as $arr) {
if ($arr['seen']==1){
echo 'SEEN';
}
}
答案 1 :(得分:0)
>>> import numpy
>>> array = numpy.array([49, 51, 53, 56])
>>> array - 13
array([36, 38, 40, 43])
如果[see]键中至少有一个是1 ,则 $seen = false;
foreach($my_array as $el){
if($el['seen']){
$seen = true;
break;
}
}
为真
如果所有[see]键都为0
$seen
为false
答案 2 :(得分:0)
采用功能方法,您可以使用测试For Each s in Sheets
Select Case s.Name
Case "Orange", "Apple", "Broccoli", "Cheese"
ActiveWorkbook.SaveAs strPath
Exit For
End Select
Next
的函数过滤数组。然后,如果结果数组非空,您知道有些元素具有'seen' == 1
值。
'seen' == 1
当然,一旦找到单个<?php
$ar = array(
0 => array(
'score' => 80,
'seen' => 1 ),
1 => array(
'score' => 4,
'seen' => 1 ),
2 => array(
'score' => 4,
'seen' => 0 )
);
if ( array_filter($ar, function($x) { return $x['seen'] == 1; }) ){
echo "Yes, at least one of [seen] keys is 1";
} else {
echo "No, all [seen] keys are 0";
}
?>
元素,此方法的效率低于突破循环的方法。但它确实在条件中给你一个表达式。
答案 3 :(得分:0)