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.

3
  • php.net/manual/ro/function.usort.php Commented Jan 21, 2015 at 15:59
  • Read about the usort() PHP function. It sorts the array using a custom comparison function provided by the programmer. Commented Jan 21, 2015 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. Commented Jan 21, 2015 at 15:59

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.