title: PHP - Validation function to return true|false, AND a message if false
body: <p>I have a validation function which returns either <code>true</code> or <code>false</code>.<br>
  However, I want it to provide info as to <em>what the problem is</em>, when there is one.</p>
  
  <p>Let's say the function is like this:</p>
  
  <pre><code>function is_valid($val) {
    $result = true;
    if( rule_1_not_met ) $result = false;
    if( rule_2_not_met ) $result = false;
    return $result;
  }
  </code></pre>
  
  <p>Which is used like this</p>
  
  <pre><code>$val = $_GET['some_param'];
  if(!is_valid($val)) $out .= 'Not so helpful feedback.';
  ...
  </code></pre>
  
  <p>I thought I could change it like this:</p>
  
  <pre><code>function is_valid($val) {
    $result = array(true, array());
    if( rule_1_not_met ) $result[1][] = 'Reason 1';
    if( rule_2_not_met ) $result[1][] = 'Reason 2';
    if(count($result[1]) &gt; 0) $result[0] = false;
    return $result;
  }
  </code></pre>
  
  <p>And use it like this:</p>
  
  <pre><code>$val = $_GET['some_param'];
  $validation_result = is_valid($val);
  if(!$validation_result[0]) $out .= implode('&lt;br/&gt;', $validation_result[1]);
  ...
  </code></pre>
  
  <p>My question is</p>
  
  <ul>
  <li><strong>Am I in, for unexpected results with this?</strong></li>
  <li><strong>Are there better ways to achieve this?</strong></li>
  </ul>
  
  <p>P.S. Would make this community wiki</p>