3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $a1 = [121, 144, 19, 161, 19, 144, 19, 11]; $a2 = [11*11, 121*121, 144*144, 19*19, 161*161, 19*19, 144*144, 19*19]; var_dump(comp($a1, $a2) === TRUE); $a1 = [121, 144, 19, 161, 19, 144, 19, 11]; $a2 = [11*21, 121*121, 144*144, 19*19, 161*161, 19*19, 144*144, 19*19]; var_dump(comp($a1, $a2) === FALSE); $a1 = [121, 144, 19, 161, 19, 144, 19, 11]; $a2 = [11*11, 121*121, 144*144, 190*190, 161*161, 19*19, 144*144, 19*19]; var_dump(comp($a1, $a2) === FALSE); $a1 = []; $a2 = []; var_dump(comp($a1, $a2) === TRUE); $a1 = []; $a2 = null; var_dump(comp($a1, $a2) === FALSE); $a1 = [121, 144, 19, 161, 19, 144, 19, 11, 1008]; $a2 = [11*11, 121*121, 144*144, 190*190, 161*161, 19*19, 144*144, 19*19]; $a1 = [10000000, 100000000]; $a2 = [10000000 * 10000000, 100000000 * 100000000]; $a1 = [10000001, 100000000]; $a2 = [10000000 * 10000000, 100000000 * 100000000]; $a1 = [2, 2, 3]; $a2 = [4, 9, 9]; function comp(array $array1 = NULL, array $array2 = NULL) : bool { $array1 = $array1 ?? []; $array2 = $array2 ?? []; $valid_comparison = $array1 && $array2 ? [[$array1, $array2]] : []; $equal_squares = array_reduce($valid_comparison, 'compare_against_squares', $array1 == $array2); return $equal_squares; } function compare_against_squares(bool $carry, array $arrays) : bool { list($array1, $array2) = $arrays; $array1_squared = array_map('square', $array1); return compare_sorted_arrays($array1_squared, $array2); } function compare_sorted_arrays(array $array1, array $array2) : bool { sort($array1); sort($array2); return $array1 == $array2; } function square(int $value) : float { return $value * $value; }
based on qrPpM
Output for hhvm-3.15.4, 7.0.0 - 7.3.0rc3
bool(true) bool(true) bool(true) bool(true) bool(false)
Output for 5.6.0 - 5.6.30
Parse error: syntax error, unexpected ':', expecting '{' in /in/QZ4OO on line 33
Process exited with code 255.