3v4l.org

run code in 300+ PHP versions simultaneously
<?php $val = array(array('price' => 700),array('price' => 1000),array('price' => 2000),array('price' => 30000),array('price' => 2000)); 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);

preferences:
30.4 ms | 402 KiB | 5 Q