title: PHP | Get input name through $_POST[]
body: <p>HTML example:  </p>
  
  <pre><code>  &lt;form method="post" id="form" action="form_action.php"&gt;
      &lt;input name="email" type="text" /&gt;
    &lt;/form&gt; 
  </code></pre>
  
  <p>User fills input field with: dfg@dfg.com</p>
  
  <pre><code>echo $_POST['email']; //output: dfg@dfg.com
  </code></pre>
  
  <p>The name and value of each input within the form is send to the server.
  Is there a way to get the name property?
  So something like..</p>
  
  <pre><code>echo $_POST['email'].name; //output: email
  </code></pre>
  
  <p>EDIT:
  To clarify some confusion about my question;</p>
  
  <p>The idea was to validate each input dynamically using a switch. I use a separate validation class to keep everything clean. This is a short example of my end result:</p>
  
  <pre><code>//Main php page
  if (is_validForm()) {
      //All input is valid, do something..
  }
  
  //Separate validation class    
  function is_validForm () {
      foreach ($_POST as $name =&gt; $value) {
          if (!is_validInput($name, $value)) return false;
      }
      return true;
     }
  
  function is_validInput($name, $value) {
      if (!$this-&gt;is_input($value)) return false; 
  
      switch($name) {
          case email: return $this-&gt;is_email($value);  
          break;
          case password: return $this-&gt;is_password($value);
          break;
  //and all other inputs
          }
      }
  </code></pre>
  
  <p>Thanks to raina77ow and everyone else!</p>