<?php
$testArray = [[
"lineupSet" => [
[[
"formula" => [
"totalPoints" => 214.61,
],
"name" => "test1",
], [
"formula" => [
"totalPoints" => 201.17,
],
"name" => "test2",
]], [
"formula" => [
"totalPoints" => 5.01,
],
"name" => "test3",
]],
],
[
"lineupSet" => [
[[
"formula" => [
"totalPoints" => 220.66,
],
"name" => "test1",
], [
"formula" => [
"totalPoints" => 214.76,
],
"name" => "test2",
]],
],
], [
"lineupSet" => [
[[
"formula" => [
"totalPoints" => 205.71,
],
"name" => "test1",
], [
"formula" => [
"totalPoints" => 204.43,
],
"name" => "test2",
]],
],
], [
"lineupSet" => [
[[
"formula" => [
"totalPoints" => 205.48,
],
"name" => "test1",
], [
"formula" => [
"totalPoints" => 203.51,
],
"name" => "test2",
]],
],
]];
function sum_points($v) {
$totalPoints = 0;
foreach ($v['lineupSet'] as $lset) {
if (isset($lset['formula'])) {
$totalPoints += $lset['formula']['totalPoints'];
}
else {
foreach ($lset as $l) {
$totalPoints += $l['formula']['totalPoints'];
}
}
}
return $totalPoints;
}
function sort_points($a, $b) {
return sum_points($b) - sum_points($a);
}
usort($testArray, 'sort_points');
print_r($testArray[0]);
- Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
- Array
(
[lineupSet] => Array
(
[0] => Array
(
[0] => Array
(
[formula] => Array
(
[totalPoints] => 220.66
)
[name] => test1
)
[1] => Array
(
[formula] => Array
(
[totalPoints] => 214.76
)
[name] => test2
)
)
)
)
preferences:
134.09 ms | 409 KiB | 5 Q