I have an array with two columns, where in the first column I have the name of a station, and in the second I have the address of the station.
I need to sort this array in alphabetical order of the station name, without losing the associated address!
I tried the array_multisort()
function, but I can only sort the columns separately. Can you help me?
This was the code used, based on the array_multisort()
function documentation. It returns the "$ data" vector still out of order, and the "$ sites" and "$ IPs" vectors are empty.
$data = array( 'sites' => $lista_estacoes, 'IPs' => $lista_enderecos);
foreach ($data as $key => $row) {
$sites[$key] = $row['sites'];
$IPs[$key] = $row['IPs'];
}
array_multisort($sites, SORT_DESC, $IPs, SORT_ASC, $data);
Where " $lista_estacoes
" and " $lista_enderecos
" are the vectors containing the data of the stations. Any mistakes I'm not aware of?
The array " $data
" looks like this:
Array
(
[sites] => Array
(
[0] =>
[1] => PrimeiraEstacao
[2] => SegundaEstacao
[3] => TerceiraEstacao
[4] =>
[5] => QuintaEstacao
...
)
[IPs] => Array
(
[0] =>
[1] => 172.168.0.11
[2] => 172.168.0.12
[3] => 172.168.0.13
[4] => 172.168.0.14
[5] => 172.168.0.15
...
)
)