我使用代码点火器。我拿到了所有的分数。我想检查一下每一个主题,我的意思是gpa=F或不。我想检查每个数组gpa=f/f使用in_array
或其他函数我不使用foreach
for
Array
(
[0] => stdClass Object
(
[id] => 5889
[name] => Dom
[student_id] => 2018000004
[roll] => 1
[class] => 6
[department] =>
[subject_type] => 0
[subject_name] => 24
[exam_type] => 1
[exam_year] => 2018
[full_mark] => 100
[getmark] => 55
[gpa] => F
[log] => 2018-11-06 20:32:33
)
[1] => stdClass Object
(
[id] => 5890
[name] => Rohim
[student_id] => 2018000006
[roll] => 1
[class] => 6
[department] =>
[subject_type] => 0
[subject_name] => 24
[exam_type] => 1
[exam_year] => 2018
[full_mark] => 100
[getmark] => 60
[gpa] => 4
[log] => 2018-11-05 19:42:26
)
)
我想检查一下。没有任何循环。
if(in_array('F',$resultList)){
echo "match";
}else {
echo "not match";
}
如果只需要知道数组中是否有F
,可以将array_column()
与in_array()
一起使用。
//Create an array of GPA's
$arr_gpa = array_column($array, 'gpa');
if(in_array('F', $arr_gpa)) {
echo "match";
} else {
echo "not match";
}