3v4l.org

run code in 300+ PHP versions simultaneously
<?php $closeStockPrice = [ 'A' => 50, 'B' => 155, 'C' => 75, 'D' => 245, 'E' => 300, 'F' => 100, 'G' => 153, ]; $average = array_sum($closeStockPrice) / count($closeStockPrice); $bestDistances = []; foreach ($closeStockPrice as $business => $price) { $distance = abs($average - $price); $current = current($bestDistances); if (!$bestDistances || $current > $distance) { $bestDistances = [$business => $distance]; } elseif ($current === $distance) { $bestDistances[$business] = $distance; } } var_export([ 'average' => $average, 'bestDistances' => $bestDistances, 'bestBusinessPrices' => array_intersect_key($closeStockPrice, $bestDistances) ]);
Output for git.master, git.master_jit, rfc.property-hooks
array ( 'average' => 154, 'bestDistances' => array ( 'B' => 1, 'G' => 1, ), 'bestBusinessPrices' => array ( 'B' => 155, 'G' => 153, ), )

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