Sort array by two specifics values in PHP
- by Roger
The folks have already showed me how to sort an array by a specific value using usort and a fallback function in PHP.
What if this specifc value doesn't exist and we have to use two values? in the example bellow the values [4] and [5]... In other words, I want to do this: order all objects numericaly by the fith value of each object from the highest to the lowest, and addicionally, for those objects that have the fifht value is empty (in the examplem '-'), order them by the fourth value.
Array(
[0] => Array(
[0] => links-patrocinados
[1] => adwords
[2] => 0,5
[3] => R$92,34
[4] => 823000
[5] => 49500
)
[1] => Array(
[0] => adwords
[1] => google adwords como funciona
[2] => 0,38
[3] => R$0,20
[4] => 480
[5] => 480
)
[2] => Array(
[0] => links-patrocinados
[1] => adword
[2] => 0,39
[3] => R$58,77
[4] => 49500
[5] => 2900
)
[3] => Array(
[0] => agencia
[1] => agencias viagens espanholas
[2] => -
[3] => R$0,20
[4] => 58
[5] => -
)
[4] => Array(
[0] => agencia
[1] => era agencia imobiliaria
[2] => -
[3] => R$0,20
[4] => 73
[5] => -
)
)