-1
$data = Array ( 
           [0] => stdClass Object ( [ID] => 1 [top_level] => gold [sub_level] => coal ) 
           [1] => stdClass Object ( [ID] => 3 [top_level] => bronze [sub_level] => dirt ) 
           [2] => stdClass Object ( [ID] => 4 [top_level] => silver [sub_level] => aluminum ) 
    )

With PHP, how can I sort, for example, by [sub_level] ascending (or descending) to produce the following?

Array ( 
       [0] => stdClass Object ( [ID] => 4 [top_level] => silver [sub_level] => aluminum ) 
       [1] => stdClass Object ( [ID] => 1 [top_level] => gold [sub_level] => coal ) 
       [2] => stdClass Object ( [ID] => 3 [top_level] => bronze [sub_level] => dirt )  
)

Also, what would be the most efficient way to search [sub_level] for a specific value?

Anas
  • 5,622
  • 5
  • 39
  • 71

1 Answers1

0

You can use usort. In the function, compare the two properties you want and return an appropriate value. Consult the suggested duplicate for more info.

Community
  • 1
  • 1
Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592