3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function makePalindrome($word) { $result = 0; $chars = str_split($word); $halfWord = round(count($chars)/2, 0, PHP_ROUND_HALF_DOWN); for($index = 0; $index >= $halfWord; $index++) { if($word != strrev($word)) { $mirrorCharPos = count($chars) - $index - 1; $mirrorChar = $chars[$mirrorCharPos]; if(isset($mirrorChar)) { $result += ord($mirrorChar) - ord($char); $chars[$mirrorCharPos] = $char; } $word = join('', $chars); }else{ break; } } return $result; } $wordToTest1 = 'aaa'; echo 'test1: ' . makePalindrome($wordToTest1) . PHP_EOL; $wordToTest2 = 'abc'; echo 'test2: ' . makePalindrome($wordToTest2) . PHP_EOL; $wordToTest3 = 'abcde'; echo 'test3: ' . makePalindrome($wordToTest3) . PHP_EOL;
based on gBkFq
Output for 5.3.0 - 7.3.1
test1: 0 test2: 0 test3: 0
Output for 5.0.4 - 5.2.17
Notice: Use of undefined constant PHP_ROUND_HALF_DOWN - assumed 'PHP_ROUND_HALF_DOWN' in /in/8akco on line 9 Warning: Wrong parameter count for round() in /in/8akco on line 9 test1: 0 Notice: Use of undefined constant PHP_ROUND_HALF_DOWN - assumed 'PHP_ROUND_HALF_DOWN' in /in/8akco on line 9 Warning: Wrong parameter count for round() in /in/8akco on line 9 Notice: Undefined variable: char in /in/8akco on line 21 Notice: Undefined variable: char in /in/8akco on line 23 Notice: Undefined variable: char in /in/8akco on line 21 Notice: Undefined variable: char in /in/8akco on line 23 test2: 197 Notice: Use of undefined constant PHP_ROUND_HALF_DOWN - assumed 'PHP_ROUND_HALF_DOWN' in /in/8akco on line 9 Warning: Wrong parameter count for round() in /in/8akco on line 9 Notice: Undefined variable: char in /in/8akco on line 21 Notice: Undefined variable: char in /in/8akco on line 23 Notice: Undefined variable: char in /in/8akco on line 21 Notice: Undefined variable: char in /in/8akco on line 23 Notice: Undefined variable: char in /in/8akco on line 21 Notice: Undefined variable: char in /in/8akco on line 23 Notice: Undefined variable: char in /in/8akco on line 21 Notice: Undefined variable: char in /in/8akco on line 23 test3: 398
Output for 5.0.2 - 5.0.3
Notice: Use of undefined constant PHP_ROUND_HALF_DOWN - assumed 'PHP_ROUND_HALF_DOWN' in /in/8akco on line 9 Warning: Wrong parameter count for round() in /in/8akco on line 9 test1: 0 Notice: Use of undefined constant PHP_ROUND_HALF_DOWN - assumed 'PHP_ROUND_HALF_DOWN' in /in/8akco on line 9 Warning: Wrong parameter count for round() in /in/8akco on line 9 Notice: Undefined variable: char in /in/8akco on line 21 Notice: Undefined variable: char in /in/8akco on line 23 Notice: Undefined variable: char in /in/8akco on line 21 Notice: Undefined variable: char in /in/8akco on line 23 test2: 197 Notice: Use of undefined constant PHP_ROUND_HALF_DOWN - assumed 'PHP_ROUND_HALF_DOWN' in /in/8akco on line 9 Warning: Wrong parameter count for round() in /in/8akco on line 9 Notice: Undefined variable: char in /in/8akco on line 21 Notice: Undefined variable: char in /in/8akco on line 23 Notice: Undefined variable: char in /in/8akco on line 21 Notice: Undefined variable: char in /in/8akco on line 23 Notice: Undefined variable: char in /in/8akco on line 21 Notice: Undefined variable: char in /in/8akco on line 23 Notice: Undefined variable: char in /in/8akco on line 21 Notice: Undefined variable: char in /in/8akco on line 23 test3: 398
Output for 5.0.0 - 5.0.1
Notice: Use of undefined constant PHP_ROUND_HALF_DOWN - assumed 'PHP_ROUND_HALF_DOWN' in /in/8akco on line 9 Warning: Wrong parameter count for round() in /in/8akco on line 9 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/8akco on line 37 test1: 0PHP_EOL Notice: Use of undefined constant PHP_ROUND_HALF_DOWN - assumed 'PHP_ROUND_HALF_DOWN' in /in/8akco on line 9 Warning: Wrong parameter count for round() in /in/8akco on line 9 Notice: Undefined variable: char in /in/8akco on line 21 Notice: Undefined variable: char in /in/8akco on line 23 Notice: Undefined variable: char in /in/8akco on line 21 Notice: Undefined variable: char in /in/8akco on line 23 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/8akco on line 39 test2: 197PHP_EOL Notice: Use of undefined constant PHP_ROUND_HALF_DOWN - assumed 'PHP_ROUND_HALF_DOWN' in /in/8akco on line 9 Warning: Wrong parameter count for round() in /in/8akco on line 9 Notice: Undefined variable: char in /in/8akco on line 21 Notice: Undefined variable: char in /in/8akco on line 23 Notice: Undefined variable: char in /in/8akco on line 21 Notice: Undefined variable: char in /in/8akco on line 23 Notice: Undefined variable: char in /in/8akco on line 21 Notice: Undefined variable: char in /in/8akco on line 23 Notice: Undefined variable: char in /in/8akco on line 21 Notice: Undefined variable: char in /in/8akco on line 23 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/8akco on line 41 test3: 398PHP_EOL
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: str_split() in /in/8akco on line 7
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Fatal error: Call to undefined function: str_split() in /in/8akco on line 7
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: str_split() in /in/8akco on line 7