3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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);
based on P6tY2
Output for 5.4.10 - 7.3.0rc4
Array ( [0] => Array ( [VAL] => TESTING [UNITS] => 99 ) [1] => Array ( [VAL] => TESTING1 [UNITS] => 99 ) [2] => Array ( [VAL] => TESTING1 [UNITS] => 88 ) )
Output for 5.3.20 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/iC48Y on line 2
Process exited with code 255.