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); 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;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8akco
function name:  (null)
number of ops:  22
compiled vars:  !0 = $wordToTest1, !1 = $wordToTest2, !2 = $wordToTest3
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   ASSIGN                                                   !0, 'aaa'
   37     1        INIT_FCALL                                               'makepalindrome'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $4      
          4        CONCAT                                           ~5      'test1%3A+', $4
          5        CONCAT                                           ~6      ~5, '%0A'
          6        ECHO                                                     ~6
   38     7        ASSIGN                                                   !1, 'abc'
   39     8        INIT_FCALL                                               'makepalindrome'
          9        SEND_VAR                                                 !1
         10        DO_FCALL                                      0  $8      
         11        CONCAT                                           ~9      'test2%3A+', $8
         12        CONCAT                                           ~10     ~9, '%0A'
         13        ECHO                                                     ~10
   40    14        ASSIGN                                                   !2, 'abcde'
   41    15        INIT_FCALL                                               'makepalindrome'
         16        SEND_VAR                                                 !2
         17        DO_FCALL                                      0  $12     
         18        CONCAT                                           ~13     'test3%3A+', $12
         19        CONCAT                                           ~14     ~13, '%0A'
         20        ECHO                                                     ~14
         21      > RETURN                                                   1

Function makepalindrome:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 16
Branch analysis from position: 49
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 45
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 39
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 49, Position 2 = 16
Branch analysis from position: 49
Branch analysis from position: 16
Branch analysis from position: 39
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
filename:       /in/8akco
function name:  makePalindrome
number of ops:  51
compiled vars:  !0 = $word, !1 = $result, !2 = $chars, !3 = $halfWord, !4 = $index, !5 = $mirrorCharPos, !6 = $mirrorChar, !7 = $char
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        ASSIGN                                                   !1, 0
    7     2        INIT_FCALL                                               'str_split'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $9      
          5        ASSIGN                                                   !2, $9
    9     6        INIT_FCALL                                               'round'
          7        COUNT                                            ~11     !2
          8        DIV                                              ~12     ~11, 2
          9        SEND_VAL                                                 ~12
         10        SEND_VAL                                                 0
         11        SEND_VAL                                                 2
         12        DO_ICALL                                         $13     
         13        ASSIGN                                                   !3, $13
   11    14        ASSIGN                                                   !4, 0
         15      > JMP                                                      ->47
   13    16    >   INIT_FCALL                                               'strrev'
         17        SEND_VAR                                                 !0
         18        DO_ICALL                                         $16     
         19        IS_NOT_EQUAL                                             !0, $16
         20      > JMPZ                                                     ~17, ->45
   15    21    >   COUNT                                            ~18     !2
         22        SUB                                              ~19     ~18, !4
         23        SUB                                              ~20     ~19, 1
         24        ASSIGN                                                   !5, ~20
   17    25        FETCH_DIM_R                                      ~22     !2, !5
         26        ASSIGN                                                   !6, ~22
   19    27        ISSET_ISEMPTY_CV                                         !6
         28      > JMPZ                                                     ~24, ->39
   21    29    >   INIT_FCALL                                               'ord'
         30        SEND_VAR                                                 !6
         31        DO_ICALL                                         $25     
         32        INIT_FCALL                                               'ord'
         33        SEND_VAR                                                 !7
         34        DO_ICALL                                         $26     
         35        SUB                                              ~27     $25, $26
         36        ASSIGN_OP                                     1          !1, ~27
   23    37        ASSIGN_DIM                                               !2, !5
         38        OP_DATA                                                  !7
   26    39    >   INIT_FCALL                                               'join'
         40        SEND_VAL                                                 ''
         41        SEND_VAR                                                 !2
         42        DO_ICALL                                         $30     
         43        ASSIGN                                                   !0, $30
         44      > JMP                                                      ->46
   29    45    > > JMP                                                      ->49
   11    46    >   PRE_INC                                                  !4
         47    >   IS_SMALLER_OR_EQUAL                                      !3, !4
         48      > JMPNZ                                                    ~33, ->16
   33    49    > > RETURN                                                   !1
   34    50*     > RETURN                                                   null

End of function makepalindrome

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
184.9 ms | 1403 KiB | 26 Q