3v4l.org

run code in 200+ php & hhvm versions
<?php $val = array(1,0,2,1,1); $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 4.3.0 - 5.6.38, hhvm-3.10.1 - 3.22.0, 7.0.0 - 7.3.1
Array ( [0] => 0 [1] => 0 [2] => 0 [3] => 0.5 [4] => 1 )