title: Php form validation with an array - print the name of a variable
body: <p>I am trying to do form validation by putting the post values into variables and those variables into an array and then cycling through them and outputting error messages for fields that are not filled in. 
  I am having two issues. Firstly, the if statement is running for all the values even if the field is empty or is == to 'undefined' and secondly i don't know how to print out the actual name of a variable instead of the variable value. For example</p>
  
  <pre><code>$variable = 'hello';
  </code></pre>
  
  <p><code>print_x($variable)//prints 'variable' instead of 'hello'</code></p>
  
  <p>I have tried two methods which are shown below.</p>
  
  <pre><code>   $error_message = "The following fields must be filled in:&lt;br /&gt;";
          $fields_to_validate_arr = array($category,$producer,$product_name,$image_name,$description,$stock_quantity,$min_sale);
          foreach($fields_to_validate_arr as $v){
              if(empty($v) || $v = 'undefined'){//using variable bariables
                  //increment the error message with a custom error message. 
                  $error_message .= "-&gt;" . ucwords(str_replace('_',' ',$v)) . "&lt;br /&gt;";//no need to use variable variables
              }
          }
  </code></pre>
  
  <p>And a different method where i use variable variables</p>
  
  <pre><code>$error_message = "The following fields must be filled in:&lt;br /&gt;";
      $fields_to_validate_arr = array('category','producer','product_name','image_name','description','stock_quantity','min_sale');
      foreach($fields_to_validate_arr as $v){
          if(empty($$v) || $$v = 'undefined'){//using variable bariables
              //increment the error message with a custom error message. 
              $error_message .= "-&gt;" . ucwords(str_replace('_',' ',$v)) . "&lt;br /&gt;";//no need to use variable variables
          }
      }
  </code></pre>
  
  <p>The variables are assigned further up in my code like </p>
  
  <pre><code>$category = myescape_function($_POST['category']);
  </code></pre>
  
  <p>Thanks</p>