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)); $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); }

preferences:
31.47 ms | 402 KiB | 5 Q