- if($a['weight'] == $b['weight']) {
- $result = strcmp($a['id'], $b['id']);
- // return -1 for equal ids to keep the behavior
- // of the original function for equal weights
- if ($result == 0) {
- return -1;
+ $cmp_order = array('weight', 'id', 'title', 'name');
+ foreach ($cmp_order as $attribute) {
+ if (isset($a[$attribute]) && isset($b[$attribute])) {
+ if ($a[$attribute] < $b[$attribute]) {
+ return -1;
+ } elseif ($a[$attribute] > $b[$attribute]) {
+ return 1;
+ } // else: $a and $b are equal wrt to this attribute, try next...