3v4l.org

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