PHP array sorting by key
<p>I have the following array for example:</p>

<pre><code>Array ( [14] =&gt; 2 [11] =&gt; 1 [7] =&gt; 2 [8] =&gt; 1 [4] =&gt; 1 )
</code></pre>

<p>Now, I can't seem to sort this by key (low - high), cause using something like arsort(); will cause a
foreach () to show a warning.</p>

<p>result needed:</p>

<pre><code>Array ( [4] =&gt; 1 [7] =&gt; 2 [8] =&gt; 1 [11] =&gt; 1 [14] =&gt; 2 )
</code></pre>

<p>how can I sort this array ?</p>

<p>Problem:</p>

<p>Warning: Invalid argument supplied for foreach() </p>

<pre><code>$hand = Explode(':', $string);

    $have = array();       
    foreach($hand as $card) {
      $ccard = Explode('-', $card);     

      If ($CPCH_TYPE == 'suit') {     
          if (!isset($have[$ccard[0]])) { $have[$ccard[0]] = 0; }
          $have[$ccard[0]]++;
      }

      ElseIf ($CPCH_TYPE == 'face') {        
          if ($ccard[1] == 1) { $ccard[1] = 14; }      
          if (!isset($have[$ccard[1]])) { $have[$ccard[1]] = 0; }
          $have[$ccard[1]]++;
      }
    }

    $have = ksort($have);

    foreach ($have As $h =&gt; $key) {      
      //do something;
    }
</code></pre>
