Sort PHP Multidimensional Array By Value

By | June 7, 2017

How to sort PHP multidimensional array by it’s value.

I have an array like this

    [0] Array
            [name] => Johny
            [age] => 14

    [1] => Array
            [name] => Ryan
            [age] => 12

    [2] => Array
            [name] => Jimmy
            [age] => 16

And I want to sort this array by “age” key. If you have the same or similar problem here is the function to sort multidimensional array by value.

// that array
function sortById($a, $b) {
   return $a['age'] - $b['age']; //the key

usort($array, 'sortById');
//new sorted array

Related Posts

agoda api

Get Hotel Details Agoda API

Get hotel detail information Agoda API by hotel id. Address, Rating, Price Range Location, Facilities, Photos, Rooms

agoda api

Get Cities In a Country Agoda API

Agoda api tutorial to get data feed of cities in a selected country with php script

agoda api

Get Country List in A Continent Agoda Api

Agoda API Toturial to get country data feed, Agoda API request to get list of all countries from selected continent.

agoda api

Gest Hotels List in A City With Agoda API

Get Hotel list in a city / area and or sub city / sub area Agoda data feed API. This api request will get data feed active hotels in a city or a sub city.

agoda api

Get List All Continents Agoda Api

Agoda API PHP tutorial & code script example to get list of all Agoda continents data feed.