validating and displaying errors from multi-dimensional array
<p>To get famous sports from counties, I created this form. </p>

<pre><code>$sports = array (
            'Australia' =&gt;  array (
                            1 =&gt; 'Cricket',
                            2 =&gt; 'Foot Ball',
                            3 =&gt; 'Net Ball',
                            4 =&gt; 'Kabadi',
                            5 =&gt; 'Ragby',
                            6 =&gt; 'Basket Ball',
                            7 =&gt; 'Volley Ball',
                        ),          
          'New Zealand' =&gt;  array (
                            1 =&gt; 'Cricket',
                            2 =&gt; 'Foot Ball',
                            3 =&gt; 'Net Ball',
                            4 =&gt; 'Ragby',
                            5 =&gt; 'Basket Ball',                         
                        ),        
              'England' =&gt;  array (
                            1 =&gt; 'Cricket',
                            2 =&gt; 'Foot Ball',
                            3 =&gt; 'Net Ball',
                            4 =&gt; 'Ragby',
                            5 =&gt; 'Karom',                           
                            6 =&gt; 'Basket Ball',                         
                            7 =&gt; 'Table Tennis',                            
                            8 =&gt; 'Tennis',                          
                        ), 
                );

echo '&lt;br&gt;&lt;form action="" method="post"&gt;';
    foreach ( $sports AS $country =&gt; $sport ) { 
        echo "&lt;h3&gt;{$country}&lt;/h3\n";    
        foreach ($sport AS $k =&gt; $v) { 
            echo "&lt;br /&gt;&lt;input type='checkbox'  name='country-sport[{$country}][]' value='{$k}' /&gt;{$v}\n";
        } 
    }
echo "\n&lt;br&gt;&lt;input type='submit' value='go' /&gt;\n&lt;/form&gt;";
</code></pre>

<p>My problem is When I am going to validate this. Here I need to check some conditions with this form validation.</p>

<ol>
<li>country-subject array is completely empty or not</li>
<li>at least 1 or upto 3 sports for each countries have selected or not </li>
</ol>

<p>these conditions not met need to display error message. </p>

<p>I tried something like this.. with this code I can get 1st error message which is if whole array is empty..</p>

<p><strong>UPDATE :</strong> this is my validation code so far..</p>

<pre><code>if ( isset($_POST['country-sport']) &amp;&amp; is_array( $_POST['country-sport'])) {

    foreach ( $_POST['country-sport'] AS $country =&gt; $sport) { 

        if ( count($sport) &gt;= 1 &amp;&amp; count($sport) &lt;= 3) { //checking that it has 3 or more values.
             //process
        } else {
            echo "select at leat 1 or upto 3 sports for {$country} ";          
        }   
    }

} else {    
    echo 'You have not selected sports for any country!';
}
</code></pre>

<p><strong>UPDATE :</strong> with var_dump($_POST['country-sport']);</p>

<pre><code>array(3) {
  ["Australia"]=&gt;
  array(3) {
    [0]=&gt;
    string(1) "1"
    [1]=&gt;
    string(1) "2"
    [2]=&gt;
    string(1) "3"
  }
  ["New Zealand"]=&gt;
  array(3) {
    [0]=&gt;
    string(1) "2"
    [1]=&gt;
    string(1) "3"
    [2]=&gt;
    string(1) "4"
  }
  ["England"]=&gt;
  array(3) {
    [0]=&gt;
    string(1) "6"
    [1]=&gt;
    string(1) "7"
    [2]=&gt;
    string(1) "8"
  }
}
</code></pre>
