title: how to store form validation errors in an array
body: <p>If I have some basic form validations, (just using empty() for simplicities sake) and want to put those error messages into an array, how would I achieve this? </p>
  
  <pre><code> $errors = array();
   $response = array();
  
  if(empty($_POST['name'])) {
  
      $errors['name'] = "Name required";
  }
  
  if(empty($_POST['email'])) {
  
      $errors['email'] = "Email required";
  }
  
  $response['errors'] = $errors;
  
  if(!empty($errors)) {
  
      $response['success'] = false;
      $response['message'] = "fail";
  
  } else {
  
      $response['success'] = true;
      $response['message'] = "&lt;div class='alert alert-success'&gt;Success&lt;/div&gt;";
  }
  
  echo json_encode($response);
  }
  </code></pre>