3v4l.org

run code in 300+ PHP versions simultaneously
<?php function get_morse() { return array(" " => "/ ", "a" => "*- ", "b" => "-*** ", "c" => "-*-* ", "d" => "-** ", "e" => "* ", "f" => "**-* ", "g" => "--* ", "h" => "**** ", "i" => "** ", "j" => "*--- ", "k" => "-*- ", "l" => "*-** ", "m" => "-- ", "n" => "-* ", "o" => "--- ", "p" => "*--* ", "q" => "--*- ", "r" => "*-* ", "s" => "*** ", "t" => "- ", "u" => "**- ", "v" => "***- ", "w" => "*-- ", "x" => "-** ", "y" => "-*-- ", "z" => "--** "); } function morse_encoder($word) { return str_replace(array_keys(get_morse()), get_morse(), strtolower($word)); } function morse_decoder($word) { $morse = array_map("trim", get_morse()); $output = ""; foreach (explode(" ", $word) as $value) { $output .= array_search($value, $morse); } return strtoupper($output); } echo morse_encoder("sos")."\n"; echo morse_decoder("*** --- ***");
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hT7c2
function name:  (null)
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   INIT_FCALL                                               'morse_encoder'
          1        SEND_VAL                                                 'sos'
          2        DO_FCALL                                      0  $0      
          3        CONCAT                                           ~1      $0, '%0A'
          4        ECHO                                                     ~1
   20     5        INIT_FCALL                                               'morse_decoder'
          6        SEND_VAL                                                 '%2A%2A%2A+---+%2A%2A%2A'
          7        DO_FCALL                                      0  $2      
          8        ECHO                                                     $2
          9      > RETURN                                                   1

Function get_morse:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hT7c2
function name:  get_morse
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E > > RETURN                                                   <array>
    5     1*     > RETURN                                                   null

End of function get_morse

Function morse_encoder:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hT7c2
function name:  morse_encoder
number of ops:  18
compiled vars:  !0 = $word
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    8     1        INIT_FCALL                                               'str_replace'
          2        INIT_FCALL                                               'array_keys'
          3        INIT_FCALL                                               'get_morse'
          4        DO_FCALL                                      0  $1      
          5        SEND_VAR                                                 $1
          6        DO_ICALL                                         $2      
          7        SEND_VAR                                                 $2
          8        INIT_FCALL                                               'get_morse'
          9        DO_FCALL                                      0  $3      
         10        SEND_VAR                                                 $3
         11        INIT_FCALL                                               'strtolower'
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                         $4      
         14        SEND_VAR                                                 $4
         15        DO_ICALL                                         $5      
         16      > RETURN                                                   $5
    9    17*     > RETURN                                                   null

End of function morse_encoder

Function morse_decoder:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 21
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 21
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/hT7c2
function name:  morse_decoder
number of ops:  27
compiled vars:  !0 = $word, !1 = $morse, !2 = $output, !3 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   11     1        INIT_FCALL                                               'array_map'
          2        SEND_VAL                                                 'trim'
          3        INIT_FCALL                                               'get_morse'
          4        DO_FCALL                                      0  $4      
          5        SEND_VAR                                                 $4
          6        DO_ICALL                                         $5      
          7        ASSIGN                                                   !1, $5
   12     8        ASSIGN                                                   !2, ''
   13     9        INIT_FCALL                                               'explode'
         10        SEND_VAL                                                 '+'
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                         $8      
         13      > FE_RESET_R                                       $9      $8, ->21
         14    > > FE_FETCH_R                                               $9, !3, ->21
   14    15    >   INIT_FCALL                                               'array_search'
         16        SEND_VAR                                                 !3
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                         $10     
         19        ASSIGN_OP                                     8          !2, $10
   13    20      > JMP                                                      ->14
         21    >   FE_FREE                                                  $9
   16    22        INIT_FCALL                                               'strtoupper'
         23        SEND_VAR                                                 !2
         24        DO_ICALL                                         $12     
         25      > RETURN                                                   $12
   17    26*     > RETURN                                                   null

End of function morse_decoder

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.07 ms | 1450 KiB | 25 Q