Below is the example code for sorting multi-dimension array by its value.
$my_array = array (
'0' => array ( 'ID' => 425, 'ln' => 'CBolware', 'fn' => 'Christian', 'mi' => '', ), '1' => array ( 'ID' => 423, 'ln' => 'Bernstein', 'fn' => 'ZBear', 'mi' => 'D.', ), '2' => array ( 'ID' => 419, 'ln' => 'DBellweather', 'fn' => 'Brent', 'mi' => '', ), '3' => array ( 'ID' => 356, 'ln' => 'ABayleaf, III', 'fn' => 'Joe', 'mi' => 'X.', ), '4 '=> array ( 'ID' => 336, 'ln' => 'Public', 'fn' => 'John', 'mi' => 'Q.', ), ); usort($my_array, function($a, $b) { return strcmp($a['fn'], $b['fn']); // fn -> key of the array });
print_r($my_array);
No comments:
Post a Comment