I have an array that contains a number of arrays. Like this:
array{
array{
id => 1
name => place_1
lat => 56.1705
lon => 10.2010
distance => 1.545
}
array{
id => 14
name => place_14
lat => 56.1715
lon => 10.2049
distance => 1.765
}
//etc etc
}
I need to sort the arrays within the array by distance, from low to high - or at least get the position of the lowest distance in the array (like $array[1][4] == 1.765).
I have done something similar before. Then I did it with a function like this:
function sort_by_dist($a, $b){
return $a['distance'] - $b['distance'];
}
usort($array, 'sort_by_dist');
However, this will in this case only return bool(true)
I have no idea why it acts this way.
I know this question has probably been asked (and answered) before, but as a non-native speaker of English I am a bit at a loss as to what I should search for.
Thank you for your help!
usortwill return a boolean as per: php.net/manual/en/function.usort.php the array$arraywill be sorted according to the function you defined (sort_by_dist)