How to Sort a Multidimensional Array by Value?

sort multidimensional array by value
Sort Multidimensional Array by Value Here’s the code from the article using the usort function to sort multidimensional array by value. usort($employeesData, function($a, $b) { return $a["Salary"] - $b["Salary"]; }); //OUTPUT /* [ ["Name" => "Mosh", "Salary" => 120000], ["Name" => "Noah", "Salary" => 220000], ["Name" => "Dany", "Salary" => 320000], ["Name" => "Robert", "Salary" => 330000], ["Name" => "Jenny", "Salary" => 440000], ["Name" => "Kylie", "Salary" => 500000], ] */ That’s one way of sorting a multidimensional array in PHP. Learn more about sorting in this article. An Example of a Multidimensional Array  A multidimensional array could be fairly complex, spanning many dimensions or arrays within arrays. However, let's keep it realistic and simulate data that closely matches a database resultset.  A Database query often returns a multidimensional array of data. For instance, here’s a snippet of a database table having rows for employee names and their annual salaries.…

read more