3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = <<<JSON { "mlb": { "james": { "avgTotalPoints": 80.675, "avgPointsDifferential": -0.8112500000000002, "rank": null }, "mary": { "avgTotalPoints": 114.9875, "avgPointsDifferential": 6.262500000000003, "rank": null }, "lucas": { "avgTotalPoints": 66.825, "avgPointsDifferential": -9.10625, "rank": null }, "timothy": { "avgTotalPoints": 69.2625, "avgPointsDifferential": -19.14125, "rank": null }, "samantha": { "avgTotalPoints": 91.625, "avgPointsDifferential": -36.85000000000001, "rank": null } }, "nhl": { "samantha": { "avgTotalPoints": 82.20000000000002, "avgPointsDifferential": 15.005714285714289, "rank": null }, "peter": { "avgTotalPoints": 77.65714285714284, "avgPointsDifferential": -13.31857142857143, "rank": null }, "rick": { "avgTotalPoints": 91.61428571428571, "avgPointsDifferential": 11.217142857142859, "rank": null }, "bubba": { "avgTotalPoints": 119.60000000000001, "avgPointsDifferential": 28.13333333333334, "rank": null }, "james": { "avgTotalPoints": 90.18571428571428, "avgPointsDifferential": 10.915714285714285, "rank": null } } } JSON; function sortHighestToLowest(array $arr): array { return array_map(static function (array $entries): array { uasort($entries, static function (array $entry1, array $entry2): int { return $entry2['avgTotalPoints'] <=> $entry1['avgTotalPoints']; }); $rank = 0; foreach ($entries as &$entry) { $entry['rank'] = ++$rank; } return $entries; }, $arr); } $arr = json_decode($json, true, 512, JSON_THROW_ON_ERROR); print_r(sortHighestToLowest($arr));
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [mlb] => Array ( [mary] => Array ( [avgTotalPoints] => 114.9875 [avgPointsDifferential] => 6.2625 [rank] => 1 ) [samantha] => Array ( [avgTotalPoints] => 91.625 [avgPointsDifferential] => -36.85 [rank] => 2 ) [james] => Array ( [avgTotalPoints] => 80.675 [avgPointsDifferential] => -0.81125 [rank] => 3 ) [timothy] => Array ( [avgTotalPoints] => 69.2625 [avgPointsDifferential] => -19.14125 [rank] => 4 ) [lucas] => Array ( [avgTotalPoints] => 66.825 [avgPointsDifferential] => -9.10625 [rank] => 5 ) ) [nhl] => Array ( [bubba] => Array ( [avgTotalPoints] => 119.6 [avgPointsDifferential] => 28.133333333333 [rank] => 1 ) [rick] => Array ( [avgTotalPoints] => 91.614285714286 [avgPointsDifferential] => 11.217142857143 [rank] => 2 ) [james] => Array ( [avgTotalPoints] => 90.185714285714 [avgPointsDifferential] => 10.915714285714 [rank] => 3 ) [samantha] => Array ( [avgTotalPoints] => 82.2 [avgPointsDifferential] => 15.005714285714 [rank] => 4 ) [peter] => Array ( [avgTotalPoints] => 77.657142857143 [avgPointsDifferential] => -13.318571428571 [rank] => 5 ) ) )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
71.15 ms | 415 KiB | 5 Q