How to display particular key value array first in php -
this question has answer here:
- how can sort arrays , data in php? 7 answers
i have array of values merged 2 array . given arrays ordered query. new merged array having in order array values.
now want order array values key 'desc' key named 'featured' contains numeric values
example
array ( [0] => stdclass object ( featured=> 0, shop_update =>a,b,c ) [1] => stdclass object ( featured=> 1, shop_update =>a,,c ), [2] => stdclass object ( featured=> 1, shop_update =>a,c ),
how order array featured desc ?
any help?
usort must help:
<?php function cmp($a, $b) { if ($a->featured == $b->featured) { return 0; } return ($a->featured < $b->featured) ? 1 : -1; } usort($array, "cmp");
Comments
Post a Comment