fork download
  1. <?php
  2.  
  3. $_POST = array(
  4. 'items_501' => 2,
  5. 'txt_501' =>'Laserjet',
  6. 'items_510' => '',
  7. 'txt_510' => 'Item Description'
  8. );
  9. $items = [];
  10. foreach($_POST as $key => $value) {
  11. //$_POST[$key] = filter($value); //POST variables are filtered for bad input
  12. $x = explode("_", $key);
  13. $itemno = $x[1];
  14. if ($x[0] == "txt") { $items[$itemno][1] = $value; }
  15. elseif ($x[0] == "items") { $items[$itemno][0] = $value; }
  16. }
  17.  
  18. foreach($items as $key => $value) {
  19. $valuestr = implode(',', $value);
  20. echo "$key: $valuestr\n";
  21. }
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
501: 2,Laserjet
510: ,Item Description