3v4l.org

run code in 500+ PHP versions simultaneously
<?php $data = [1, 5, 12, 15, 20, 25,]; function getDifferences($aValues) { $aDiff = []; $iSize = count($aValues); for ($i = 0; $i < $iSize; $i++) { for ($j = $i + 1; $j < $iSize; $j++) { $aDiff[$aValues[$i]][] = abs($aValues[$i] - $aValues[$j]); } } return $aDiff; } function printDifferences($aValues){ foreach ($aValues as $iNumber => $aDiffs){ echo "Differences for $iNumber: " . implode(', ', $aDiffs) . PHP_EOL; } } $aDiff = getDifferences($data); printDifferences($aDiff);

preferences:
48.55 ms | 2027 KiB | 5 Q