I need to sort a multi-dimensional, non-associative array on the 2nd field. I read the data in from a simple CSV file. The first value is string and the second is a number. If there is no easy way to do this with a simple function, then is there a way to convert a non-associative array to an associative array so that I can sort an associative array using the function below?
Code:
// from php.net
function sortArrayByField( $original, $field, $descending = false )
{
$sortArr = array();
foreach ( $original as $key => $value )
{
$sortArr[ $key ] = $value[ $field ];
}
if ( $descending )
{
arsort( $sortArr );
}
else
{
asort( $sortArr );
}
$resultArr = array();
foreach ( $sortArr as $key => $value )
{
$resultArr[ $key ] = $original[ $key ];
}
return $resultArr;
}