Wednesday, June 29, 2016

Sorting a multidimensional associative array by key's value using usort in PHP

This post explains how a multidimensional associative array in PHP can be sorted by value of one of the associative keys. It can also be described as sorting an array of arrays by the keys of sub-arrays. Let us understand the situation with an example. Suppose there is a PHP array shown in the PHP code below:
<?php
$multi_array = array(array('name' => 'Orange', 'code' => '18plkp', 'value' => 15),
                     array('name' => 'Apple', 'code' => '45jklp', 'value' => 49),
                     array('name' => 'Guava', 'code' => '48pyhp', 'value' => 169)
                    );
var_dump($multi_array);
?>