title: Using usort in php to sort an array of objects?
body: <p>I did look at usort, but am still a little confused...  </p>
  
  <p>Here is what the $myobject object looks like:</p>
  
  <pre><code>Array
  (
      [0] =&gt; stdClass Object
          (
              [tid] =&gt; 13
              [vid] =&gt; 4
          )
  
      [1] =&gt; stdClass Object
          (
              [tid] =&gt; 10
              [vid] =&gt; 4
          )
  
      [2] =&gt; stdClass Object
          (
              [tid] =&gt; 34
              [vid] =&gt; 4
          )
  
      [3] =&gt; stdClass Object
          (
              [tid] =&gt; 9
              [vid] =&gt; 4
          )
  </code></pre>
  
  <p>I saw this: </p>
  
  <pre><code>function cmp( $a, $b )
  { 
    if(  $a-&gt;weight ==  $b-&gt;weight ){ return 0 ; } 
    return ($a-&gt;weight &lt; $b-&gt;weight) ? -1 : 1;
  } 
  usort($myobject,'cmp');
  </code></pre>
  
  <p>I'm trying to sort according to tid, but, I guess I'm just not sure really if I have to change weight to something?  Or will it just work as is?  I tried it, but nothing outputted... </p>