0

I have an array of values which was merged by two array . The given arrays are ordered by some query. Now i the new merged array having in order array values.

Now I want to order that array values by key 'desc' key named 'featured' it 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 to order this array by featured desc ?

Any help?

Aaru
  • 803
  • 4
  • 13
  • 29

1 Answers1

0

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");
user4035
  • 22,508
  • 11
  • 59
  • 94