3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $val = array(array('price' => 700),array('price' => 1000),array('price' => 2000),array('price' => 30000),array('price' => 2000)); $subtract = 3.5; foreach($val as $item){ foreach($item as $key => $items) { if ($subtract > $items){ $subtract -= $items; $item[$key] = 0; } else{ $item[$key] -= $subtract; $subtract = 0; } } print_r($item); }
Output for 5.6.30, hhvm-3.15.4 - 3.22.0, 7.0.0 - 7.3.0beta2
Array ( [price] => 696.5 ) Array ( [price] => 1000 ) Array ( [price] => 2000 ) Array ( [price] => 30000 ) Array ( [price] => 2000 )