Skip to content

Instantly share code, notes, and snippets.

@ninnypants
Created November 11, 2011 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ninnypants/1359045 to your computer and use it in GitHub Desktop.
Save ninnypants/1359045 to your computer and use it in GitHub Desktop.
Sort an array by column
<?php
function arr_sort_by_column($arr_data, $str_column, $bln_desc = false)
{
$arr_data = (array) $arr_data;
$str_column = (string) trim($str_column);
$bln_desc = (bool) $bln_desc;
$str_sort_type = ($bln_desc) ? SORT_DESC : SORT_ASC;
foreach ($arr_data as $key => $row)
{
${$str_column}[$key] = $row[$str_column];
}
array_multisort($$str_column, $str_sort_type, $arr_data);
return $arr_data;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment