function sort_searches($a, $b)
{
return
(
(isset($b['Class_ID']) && !isset($a['Class_ID']))
||
($b['Results'] && !$a['Results'])
||
(is_array($a['Results']) && !$a['Results'] && !is_array($b['Results']))
);
}
I'm using this function in usort(). The intended effect is that a list of searches will be sorted first by whether they have Class_IDs, and then second by results (with a non-empty array of results > results === false > results === empty array(). So a sorted set of searches would look like:
Class_ID with results
Class_ID with results === false
Class_ID with results === array()
No Class_ID with results
No Class_ID with results === false
No Class_ID with results === array()
Currently the functions sorts on results completely fine, but not on whether a search has a Class_ID.
usort($searches, 'sort_searches')