3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $closestRadix = function(int $num) : int { $index = floor(log($num, 10)); $nextMag = 10**($index+1); return $nextMag - $num > $nextMag / 2 ? $index: $index + 1; }; $numDigits = function(int $num) : int { return floor(log($num, 10)) + 1; }; $isEven = function(int $num) : bool { return $num % 2 == 0; }; $isEvenNumberOfDigits = function(int $num) : bool { return $isEven($numDigits($num)); }; $mirror = function(int $num, bool $parityCase = false) : int { echo $num . "\n"; return (int)($parityCase ? substr((string)$num, 0, -1) : (string)$num . strrev((string)$num)); }; $halves = function(int $num) use ($isEvenNumberOfDigits, $numDigits) : array { $digitsPerHalf = $isEvenNumberOfDigits ? $numDigits($num)/2 : ceil($numDigits($num)/2); return [ substr((string)$num, 0, $digitsPerHalf), substr((string)$num, $digitsPerHalf, $digitsPerHalf) ]; }; $nextPalindrome = function(int $num) use ($halves, $mirror) : int { print_r($halves($num)); $smallestHalf = min($halves($num)); echo $smallestHalf . "\n"; return $halves($num)[0] == $smallestHalf ? $mirror($halves($num)[0])+1 : $mirror($halves($num)[1]); }; echo $nextPalindrome(110); ?> === 110 120 -> 121 999 1312 1314 -> 1331 121 131 191 202 1221 3113 9999
based on pIMmG
Output for hhvm-3.18.4 - 3.21.0, 7.0.0 - 7.3.0rc3
Array ( [0] => 1 [1] => 1 ) 1 1 12 === 110 120 -> 121 999 1312 1314 -> 1331 121 131 191 202 1221 3113 9999
Output for 5.6.0 - 5.6.30
Parse error: syntax error, unexpected ':', expecting '{' in /in/jLTBq on line 3
Process exited with code 255.