3v4l.org

run code in 300+ PHP versions simultaneously
<?php function makePalindrome($word) { $result = 0; $chars = str_split($word); $halfWord = round(count($chars)/2, 0, PHP_ROUND_HALF_DOWN); var_dump($halfWord);exit; 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;
Output for git.master, git.master_jit, rfc.property-hooks
float(1)

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:
64.36 ms | 401 KiB | 8 Q