php - Sort array of objects -


I have had problems with the PHP manual, so I want to ask it here ...

I have an array of objects. Is there a way to sort on the content of the object?

For example, my array is:

  Array ([0] => Study Class Object ([ID] => 123 [alias] = & Gt; Mike) [1] => Study Class Object ([ID] => [456] [nickname] => Elise) [2] => Study Class Object ([ID] = & gt; ; 789 [nickname] = & gt; Zeke] [3] => Study Class Object ([ID] => 987 [nickname] => DAVE])  

In the example, the output should be:

  Array ([0] => Study Class object. How do I determine the array by the object's [nickname]  

([Id] = & gt; 456 [nickname] => alice) [1] = gt; StdClass object ([ID] => 987 [nickname] => DAVE] [2] => ; StdClass object ([ID] => 123 [nickname] => Mike) [3] =>

Post-text "itemprop =" text ">

You specify the function to compare and sort based on the function, eg:

  function my_comparison ($ a, $ b) {return strcmp ($ a- & gt; Last name, $ b- & gt; Surname); } $ Arr = ...; Usart ($ arr, 'my_comparison');  

Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -