1

I try to find any solution with sort multi-dimensional arrays, but don't see anything match my requirement.

Here is my example that I want.

I want to sort below array by "views" DESC

$arr = array(
0=>array(
    'id'=>11,
    'views'=>10,
    'title'=> 'html'
),
1=>array(
    'id'=>12,
    'views'=>4,
    'title'=> 'Java'
),
2=>array(
    'id'=>13,
    'views'=>100,
    'title'=> 'Boostrap'
)
);

to

$arr = array(
0=>array(
    'id'=>13,
    'views'=>100,
    'title'=> 'Boostrap'
),
1=>array(
    'id'=>11,
    'views'=>10,
    'title'=> 'html'
),
2=>array(
    'id'=>12,
    'views'=>4,
    'title'=> 'Java'
)
);

without loop in php.

How can I do this.

  • https://php.net/manual/ro/function.usort.php – Sergiu Paraschiv Jan 21 '15 at 15:59
  • Read about the [`usort()`](http://php.net/manual/en/function.usort.php) PHP function. It sorts the array using a custom comparison function provided by the programmer. – axiac Jan 21 '15 at 15:59
  • why would you have a restriction for something as basic as a loop? even if you find a predefined function it will use a loop in the background. – oshell Jan 21 '15 at 15:59

0 Answers0