Someone please help me out this issue.
This is my array - I want to order by shop_featured and 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 the below functions for 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