- array_push: documentation ( source)
- strpos: documentation ( source)
- print_r: documentation ( source)
<?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);