How to Sort Multidimensional Array using key in PHP

Spread the love

For Example you an Multidimensional array ,with value of “Salons” in a city.This Array is also containing Saloon Price and saloon name.Now you want to print or get saloons in ASCENDING Order based on Saloon Price.

Example :

This Will Print :

Now we want to sort this array by the value of the “price” key.As of PHP 7, this can be done concisely using usort with an anonymous function that uses the spaceship operator to compare elements.

How to Use

You can do an ascending sort like this:


as you can see now all saloons are coming by “price ascending order”.and You can do an desccending sort like this:

Leave a Reply

Your email address will not be published. Required fields are marked *