function CHECKITEMEXIST($cartarray, $sub){
foreach ($cartarray as $item){
foreach ($item as $item2){
if($item2['subject'] = $sub){
return '1';
}else{
return '0';
}
}
}
}
$subject = "English";
$checkitemexist = CHECKITEMEXIST($cart, $subject);
if($checkitemexist > 0){
echo "Yes";
}else{
echo "No";
}
Guys I have the function below to check my cart array to see whether english subject exist or not, but the problem is even when english isn't in the cart array it will still return yes result, why is that so?
Below are the sample cart array.
Array ( [0] => Array ( [0] => Array ( [subject] => science ) ) )
'0'and'1', you should change that to0and1. Stick with integers as much as you reasonably can (for performance). Also, on line4 on the 2nd piece of code you do>0. I suggest either!==0or===1. These are a tiny bit faster, but I personally because IMO it reads easiertrue/falseand doif( $checkitemexist ){