3v4l.org

run code in 300+ PHP versions simultaneously
<?php function sortAvg($array){ $a = array_slice($array, 0); $avg = array_sum($a)/count($a); echo $avg . "\n"; uasort($a, function($o, $b) use($avg){ return abs($o-$avg) > abs($b-$avg); }); return $a; } $array = [ 'A' => 50, 'B' => 155, 'C' => 75, 'D' => 245, 'E' => 300, 'F' => 100, 'G' => 153, ]; $results = sortAvg($array); $closestKey = array_keys($results)[0]; $closestValue = $results[$closestKey]; var_export([$closestKey, $closestValue]);
Output for git.master, git.master_jit, rfc.property-hooks
154 Deprecated: uasort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in /in/lhmfg on line 7 array ( 0 => 'B', 1 => 155, )

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:
35.65 ms | 405 KiB | 5 Q