I want to check fruit name in array and check if color value is 1. Its showing error Cannot use object of type stdClass as array
if(checkFruits('apple','red')){
//ok
}
function checkFruits($fruit = null, $color = null) {
$fruits = Array ( [0] => stdClass Object ( [id] => 1 [fruit] => apple [red] => 1 [yellow] => 0 [1] => stdClass Object ( [id] => 2 [fruit] => orange [red] => 0 [yellow] => 1 ) );
foreach($fruits as $val){
if($val['fruit'] == $fruit && $val[$color] == 1){
return true;
}
}
return false;
}