3
I have a random array containing in its keys, an alphanumeric sequence. Using the function ksort, get the following result:
array(22) {
["A1"]=>
string(2) "A1"
["A10"]=>
string(3) "A10"
["A11"]=>
string(3) "A11"
["A12"]=>
string(3) "A12"
["A2"]=>
string(2) "A2"
["A4"]=>
string(2) "A4"
["A5"]=>
string(2) "A5"
}
However, sorting should prioritize the numerical order of the keys. The expected result is:
array(22) {
["A1"]=>
string(2) "A1"
["A2"]=>
string(3) "A2"
["A4"]=>
string(2) "A4"
["A5"]=>
string(2) "A5"
["A10"]=>
string(2) "A10"
["A11"]=>
string(3) "A11"
["A12"]=>
string(3) "A12"
}
The sort made by ksort is correct, because its key is text and not number ...
– Cezar
What you want would be to basically separate the
string
number first ordering by string a apos by number, correct?– Guilherme Lautert
@Guilhermelautert he wants to order by number looks at the second example which is the output
– Cezar
Both are correct. I need to sort both by letter and by number as I exemplified the expected result.
– Marcelo de Andrade
@Marcelodeandrade but which the priority the letter or the number?
– Guilherme Lautert
The letter, then the number. A1 A2 A13 B2 B3 B10 etc...
– Marcelo de Andrade
The
A
is fixed? if yes can cut it off and adicioanar after.– rray
My example was just a small demo, @rray. The array can contain values from A1-A99 to Z1-Z99.
– Marcelo de Andrade