title: Sorting an array of SimpleXML objects
body: <p>I've read what I've found on Stackoverflow and am still unclear on this.</p>
  
  <p>I have an array of SimpleXML objects something like this:</p>
  
  <pre><code>array(2) {
    [0]=&gt;
    object(SimpleXMLElement)#2 (2) {
      ["name"]=&gt;
      string(15) "Andrew"
      ["age"]=&gt;
      string(2) "21"
    }
    [1]=&gt;
    object(SimpleXMLElement)#3 (2) {
      ["name"]=&gt;
      string(12) "Beth"
      ["age"]=&gt;
      string(2) "56"
    }
  }
  </code></pre>
  
  <p>And I want to be able to sort by whatever column, ascending or descending. Something like:</p>
  
  <pre><code>sort($data, 'name', 'asc');
  </code></pre>
  
  <p>Where I can pass in the above array of objects and sort by the value of whichever key I like. </p>
  
  <p>For reference, a similar .NET solution would be along these lines:</p>
  
  <pre><code>XmlSortOrder order = XmlSortOrder.Ascending;
      if ( sortDirection == "asc" ) {
          order = XmlSortOrder.Ascending;
      }
      expression.AddSort( columnSortingOn + "/text()", order, 
          XmlCaseOrder.UpperFirst, "en-us", XmlDataType.Text ); 
  </code></pre>
  
  <p>I've seen people say </p>
  
  <blockquote>
    <p>"Use usort"</p>
  </blockquote>
  
  <p>Followed by a basic example from the PHP manual but this doesn't really explain it. At least not to me. I've also seen people suggest using an external library like SimpleDOM but I want to avoid using something external for this (seemingly, though I cannot yet solve it) little thing.</p>
  
  <p>Any help is appreciated, Thanks!</p>