title: How do I sort an array by string length then by value in PHP?
body: <p>Currently, I have my array sorting by string length. But, when the string lengths are equal, how do I sort by value?</p>
  
  <p>As an example, my current code:  </p>
  
  <pre><code>$array = array("A","BC","AA","C","BB", "B");
  
  function lensort($a,$b){
      return strlen($a)-strlen($b);
  }
  
  usort($array,'lensort');
  
  print_r($array);
  </code></pre>
  
  <p>Outputs:</p>
  
  <pre><code>Array
  (
      [0] =&gt; C
      [1] =&gt; A
      [2] =&gt; B
      [3] =&gt; BB
      [4] =&gt; AA
      [5] =&gt; BC
  )
  </code></pre>
  
  <p>But, I'd like it to sort by the following instead:</p>
  
  <pre><code>Array
  (
      [0] =&gt; A
      [1] =&gt; B
      [2] =&gt; C
      [3] =&gt; AA
      [4] =&gt; BB
      [5] =&gt; BC
  )
  </code></pre>