title: Sort PHP array by numerical values
body: <p>I would like to sort the following names</p>
  
  <pre><code>Array ( [Jessie] =&gt; 2 [Sarah] =&gt; 3 [Simon] =&gt; 2 [John] =&gt; 2 [Kevin] =&gt; 1 [Canvasser] =&gt; 8 [canvasser] =&gt; 11 )
  </code></pre>
  
  <p>based on the values corresponding to them</p>
  
  <p>I printed the names through the following function </p>
  
  <pre><code>// get canvasser individual names and count houses canvassed
      foreach ($canvassers as $key =&gt; $value) {
          // Add to the current group count if it exists
          if ( isset( $canvasser_counts[$value] ) ) {
              $canvasser_counts[$value]++;
          }
          // or initialize to 1 if it doesn't exist
          else {
              $canvasser_counts[$value] = 1;
          }
      }
      print_r($canvasser_counts);
  </code></pre>
  
  <p>where $canvassers simply held all the names eg.</p>
  
  <pre><code>$canvassers = array('Jessie', 'Simon', 'Jessie')
  </code></pre>
  
  <p>Any help would be really appreciated, I have spent so long on this but can't get my head straight to sort the array correctly.</p>