array(4) {
[D.Fletcher] = array(22) {
[games] = int() 2
[ab] = int() 6
[runs] = int() 2
[hits] = int() 2
}
[A.Slegers] = array(22) {
[games] = int() 3
[ab] = int() 0
[runs] = int() 0
[hits] = int() 0
}
[A.Eaton] = array(22) {
[games] = int() 1
[ab] = int() 2
[runs] = int() 0
[hits] = int() 0
}
[S.Ohtani] = array(22) {
[games] = int() 3
[ab] = int() 6
[runs] = int() 2
[hits] = int() 3
}
I want to be able to sort the array starting at the third character of the key.
If I use ksort, I get:
A.Eaton
A.Slegers
D.Fletcher
S.Ohtani
But I want:
A.Eaton
D.Fletcher
S.Ohtani
A.Slegers
I can do this SQL as follows: SELECT * FROM batters order by SUBSTRING(name, 3)
But I cannot figure out how to do it with a PHP sort. I know I can get the keys with
$keys=array_keys($arr);
or in a loop:
foreach ($arr as $key => $value) {
echo $key;
}
Then possibly do a substr($key, 3) but I can't figure out how to put it all together for a sort.