3v4l.org

run code in 300+ PHP versions simultaneously
<?php function makePalindrome($word){ $result = 0; $chars = str_split($word); foreach($chars as $index => $char){ $ascii = ord($char); if($index==$ascii-97){ $result+=$ascii-97; } } return $result; } $test='abcde'; echo makePalindrome($test);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vOgk1
function name:  (null)
number of ops:  6
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   ASSIGN                                                   !0, 'abcde'
   24     1        INIT_FCALL                                               'makepalindrome'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $2      
          4        ECHO                                                     $2
          5      > RETURN                                                   1

Function makepalindrome:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 19
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 19
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 18
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/vOgk1
function name:  makePalindrome
number of ops:  22
compiled vars:  !0 = $word, !1 = $result, !2 = $chars, !3 = $char, !4 = $index, !5 = $ascii
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                                         $7      
          5        ASSIGN                                                   !2, $7
    9     6      > FE_RESET_R                                       $9      !2, ->19
          7    > > FE_FETCH_R                                       ~10     $9, !3, ->19
          8    >   ASSIGN                                                   !4, ~10
   11     9        INIT_FCALL                                               'ord'
         10        SEND_VAR                                                 !3
         11        DO_ICALL                                         $12     
         12        ASSIGN                                                   !5, $12
   13    13        SUB                                              ~14     !5, 97
         14        IS_EQUAL                                                 !4, ~14
         15      > JMPZ                                                     ~15, ->18
   15    16    >   SUB                                              ~16     !5, 97
         17        ASSIGN_OP                                     1          !1, ~16
    9    18    > > JMP                                                      ->7
         19    >   FE_FREE                                                  $9
   20    20      > RETURN                                                   !1
   21    21*     > RETURN                                                   null

End of function makepalindrome

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.62 ms | 1390 KiB | 18 Q