3v4l.org

run code in 300+ PHP versions simultaneously
<?php function do_split($name) { return preg_split('/([A-Z]{2,}|([A-Z][^A-Z]*))/', $name, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); } function convert_case($name) { return implode( '_', array_map( 'strtolower', do_split($name) ) ); } function convert_case2($name) { $output = ''; for ($i=0; $i<strlen($name); $i++) { $char = $name[$i]; print_r("{$char} " . json_encode(ctype_upper($char))); } return strtolower($output); } convert_case2('FooBARbar'); $samples = array( 'FooBar', 'FooBAR', 'FOObar', 'foo_bar', 'FOO_bar', 'foo_BAR', 'foo_Bar', 'Foo_bar', ); /* print_r(array_map(function ($name) { return array( 'name' => $name, 'split' => do_split($name), 'converted' => convert_case($name), ); }, $samples)); */
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qPNjh
function name:  (null)
number of ops:  5
compiled vars:  !0 = $samples
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   INIT_FCALL                                               'convert_case2'
          1        SEND_VAL                                                 'FooBARbar'
          2        DO_FCALL                                      0          
   28     3        ASSIGN                                                   !0, <array>
   48     4      > RETURN                                                   1

Function do_split:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qPNjh
function name:  do_split
number of ops:  9
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'preg_split'
          2        SEND_VAL                                                 '%2F%28%5BA-Z%5D%7B2%2C%7D%7C%28%5BA-Z%5D%5B%5EA-Z%5D%2A%29%29%2F'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 null
          5        SEND_VAL                                                 3
          6        DO_ICALL                                         $1      
          7      > RETURN                                                   $1
    5     8*     > RETURN                                                   null

End of function do_split

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

End of function convert_case

Function convert_case2:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 4
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 4
Branch analysis from position: 22
Branch analysis from position: 4
filename:       /in/qPNjh
function name:  convert_case2
number of ops:  27
compiled vars:  !0 = $name, !1 = $output, !2 = $i, !3 = $char
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   18     1        ASSIGN                                                   !1, ''
   19     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->19
   20     4    >   FETCH_DIM_R                                      ~6      !0, !2
          5        ASSIGN                                                   !3, ~6
   21     6        INIT_FCALL                                               'print_r'
          7        NOP                                                      
          8        FAST_CONCAT                                      ~8      !3, '+'
          9        INIT_FCALL                                               'json_encode'
         10        INIT_FCALL                                               'ctype_upper'
         11        SEND_VAR                                                 !3
         12        DO_ICALL                                         $9      
         13        SEND_VAR                                                 $9
         14        DO_ICALL                                         $10     
         15        CONCAT                                           ~11     ~8, $10
         16        SEND_VAL                                                 ~11
         17        DO_ICALL                                                 
   19    18        PRE_INC                                                  !2
         19    >   STRLEN                                           ~14     !0
         20        IS_SMALLER                                               !2, ~14
         21      > JMPNZ                                                    ~15, ->4
   23    22    >   INIT_FCALL                                               'strtolower'
         23        SEND_VAR                                                 !1
         24        DO_ICALL                                         $16     
         25      > RETURN                                                   $16
   24    26*     > RETURN                                                   null

End of function convert_case2

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
181.34 ms | 1403 KiB | 29 Q