I want to return the matching item's value in foreach loop. I have tried with the blow code but it is not returning correctly. If the matches with the last item, it won't returns the correct value.
//$bonuses = count => amount
Array
(
[15] => 25
[30] => 50
[46] => 100
)
// getting keys to compare the count
$counts = array_keys($bonuses);
foreach ($bonuses as $count => $bonus) {
if ($total_number_of_products <= next($counts)) {
$tti = 'Items: '. $total_number_of_products. ' Bonus: '. $bonus. '<BR/>';
}
}
The loop should returns the item if less than or equal. If the count is 46 or higher (in this case) the output should 100. Now it is returning 50.