<?php
/**
* Sort an array of array, by a specific column in the sub-arrays
*
* $id$
*
* @file function.array_columnsort.php
* @author Tobias H. michaelsen <thm-hide@address.com>
* @date 2000-11-03
*
* @param &$arr Pointer to the array that is to be sorted
* @param $col Name or index of the column to sort by
*/
function array_columnsort(&$arr, $col) {
$GLOBALS['i3t27ftr4'] = $col;
usort($arr, "custom_compare_function");
}
// {{{ custom compare function
function custom_compare_function($a, $b) {
global $i3t27ftr4;
if (!is_array($a) or !is_array($b)) {
return 0;
} elseif (is_string($a[$i3t27ftr4]) and is_string($b[$i3t27ftr4])) {
return strnatcmp($a[$i3t27ftr4], $b[$i3t27ftr4]);
} elseif (is_numeric($a[$i3t27ftr4]) and is_numeric($b[$i3t27ftr4])) {
if ($a[$i3t27ftr4] == $b[$i3t27ftr4]) return 0;
else return ($a[$i3t27ftr4] < $b[$i3t27ftr4]) ? -1 : 1;
} else { // unknown type
return 0;
}
}
// }}}
/* vim: set tabstop=4: */
?>