Assign POST/GET to internal array


/ Published in: PHP
Save to your folder(s)

I'm working on a web app that requires me to track nearly 300 form fields. To make this easier, and to allow me to handle special cases, I needed to assign them to an internal array. The switch/case statement makes this a breeze.


Copy this code and paste it in your HTML
  1. <?php
  2. // Loop through the fields in the POST and assign them to our internal variable.
  3. // There are several special cases we need to handle differently, so we'll skip
  4. // them for now.
  5. foreach($_POST as $key=>$value) {
  6. switch($key) {
  7. case 'submit'; // Completely skip over the submit button
  8. case "field_1";
  9. case "/^a\ regex$/";
  10. case "field_20";
  11. default:
  12. $myArray[$key] = $value;
  13. }
  14. }
  15. ?>

URL: http://www.r1designs.net

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.