Reputation: 303
I would like to check if
$price_a = 30;
is greater than all the values in
$all_prices = [
1 => 12,
2 => 24,
3 => 32,
4 => 44
];
I guess I'd have to loop through the array and do the check for each iteration but I'm not sure how that loop should look like. Or is there a simpler solution?
Upvotes: 3
Views: 80
Reputation: 722
You can use the max function in array
http://php.net/manual/en/function.max.php
echo max(2, 3, 1, 6, 7); // 7
Upvotes: 1
Reputation: 330
You can check it by using max function of php :
<?php
if($price_a > max($all_prices)){
echo "Greater than all the values";
}
else{
echo "Smaller than ".max($all_prices);
}
?>
Upvotes: 4