title: PHP: checking key value is not empty
body: <p>I wrote a small function to check the required fields of a form, are not empty.
  The function accepts two arguments, 1st is an array with all values from $_POST superglobal.
  2nd is the required fields array which I populate.</p>
  
  <p>Have a look:</p>
  
  <pre><code>public $errors = array();
  
  public function validate_fields($fields_array, $required_fields) 
  {
      foreach ($required_fields as $key =&gt; $value)
      {
          if (array_key_exists($key, $fields_array)) 
          {
              # If key exists in $fields_array
              # check that the key value inside $fields_array is set &amp; isn't empty
              # if it's empty, populate with an error
              if(empty($fields_array[$key][$value]))
              {
                  $this-&gt;errors[] = "{$key} is empty but in fields_array";
              }
          }
          else 
          {
              # Key does not exists in $fields_array
              # Did someone temper with my html ?
              $this-&gt;errors[] = "{$key} is not in fields_array";
          }
      }
      return (empty($this-&gt;errors)) ? true : false;
  }     
  </code></pre>
  
  <p>The issue I'm having seems to be related to "if(empty($fields_array[$key][$value]))"
  statement. my goal is to check that $fields_array key value is not empty based on $required_fields key. I'm sure the statement I'm using is off. If you see anything that you think can be written better, please let me know, as I am new to php. Appreciate the help.</p>