3v4l.org

run code in 300+ PHP versions simultaneously
<?php $_POST = ['VAL0' => 'TESTING', 'UNIT0' => '99', 'VAL1' => 'TESTING1', 'UNITS1' => '88']; $bulkProducts = array(); foreach ($_POST as $key => $value) { if (strpos($key, "VAL")===0) { $val= $value; } if (strpos($key, "UNIT")===0) { $newunits= $value; } if (isset($val,$newunits)) { $products = array(); $products = array( 'VAL' => $val, 'UNITS' =>$newunits ); array_push($bulkProducts,$products); } } print_r($bulkProducts);

preferences:
52.93 ms | 402 KiB | 5 Q