Sorting multidimensional array on two columns in PHP -


someone please me out issue.

this array - want order shop_featured , counts.

array (     [0] => stdclass object         (             [shop_id] => 1             [shop_featured] => 1             [counts] => 20         )      [1] => stdclass object         (             [shop_id] => 484             [shop_featured] => 1             [counts] => 9         )      [2] => stdclass object         (             [shop_id] => 886             [shop_featured] => 0             [counts] => 0         )      [3] => stdclass object         (             [shop_id] => 1279             [shop_featured] => 0             [counts] => 0         )      [4] => stdclass object         (             [shop_id] => 861             [shop_featured] => 0             [counts] => 0         )      [5] => stdclass object         (             [shop_id] => 242             [shop_featured] => 0             [counts] => 0         )      [6] => stdclass object         (             [shop_id] => 1187             [shop_featured] => 0             [counts] => 0         )      [7] => stdclass object         (             [shop_id] => 906             [shop_featured] => 0             [counts] => 2         )      [8] => stdclass object         (             [shop_id] => 297             [shop_featured] => 0             [counts] => 9         )      [9] => stdclass object         (             [shop_id] => 838             [shop_featured] => 0             [counts] => 9         )      [10] => stdclass object         (             [shop_id] => 1181             [shop_featured] => 0             [counts] => 2         )      [11] => stdclass object         (             [shop_id] => 620             [shop_featured] => 0             [counts] => 0         )  ) 

i used below functions this

usort($value, array('model_shop', 'cmp1')); usort($value, array('model_shop', 'cmp'));   function cmp($a, $b) {     if ($a->shop_featured == $b->shop_featured) {     return 0;     }     return ($a->shop_featured < $b->shop_featured) ? 1 : -1; }  function cmp1($a, $b) {     if ($a->counts == $b->counts) {     return 0;     }     return ($a->counts < $b->counts) ? 1 : -1; } 

advance thanks

something should sort shop_featured, counts

usort($value, array('model_shop', 'cmp'));  function cmp($a, $b) {     if ($a->shop_featured == $b->shop_featured) {         if ($a->counts == $b->counts) {             return 0;         }         return ($a->counts < $b->counts) ? 1 : -1;     }     return ($a->shop_featured < $b->shop_featured) ? 1 : -1; } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -