Below I have an array that I generate, I need to order each by the 3rd [2] values.
Array:
{
aknox: {
0: "28",
1: "39",
2: "71.79"
},
lphillips: {
0: "81",
1: "106",
2: "76.42"
}
}
Expected result:
{
lphillips: {
0: "81",
1: "106",
2: "76.42"
},
aknox: {
0: "28",
1: "39",
2: "71.79"
}
}
I have tried the following:
usort($ccstats, function($a, $b) {
return strcmp($a[2], $b[2]);
});
$ccstats being the array.
This returns the array in ascending order when I tried to make array keys in descending order i.e. "akonx" and "lphillips" get lost and turned into 0 and 1
Any help appreciated
uasortand the inverse of what you havestrcmp($b[2], $a[2]);