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) { $words = array(); $prev = ''; for ($i = 0; $i < strlen($name); $i++) { $char = $name[$i]; echo "{$char} " . (ctype_upper($char) ? 'true' : 'false') . "\n"; } return strtolower(implode('_', $words)); } convert_case2('FooBARbar0123'); $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/JRXtk
function name:  (null)
number of ops:  5
compiled vars:  !0 = $samples
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   INIT_FCALL                                               'convert_case2'
          1        SEND_VAL                                                 'FooBARbar0123'
          2        DO_FCALL                                      0          
   29     3        ASSIGN                                                   !0, <array>
   49     4      > RETURN                                                   1

Function do_split:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JRXtk
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/JRXtk
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 = 20
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 5
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 15
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 5
Branch analysis from position: 23
Branch analysis from position: 5
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 5
Branch analysis from position: 23
Branch analysis from position: 5
filename:       /in/JRXtk
function name:  convert_case2
number of ops:  32
compiled vars:  !0 = $name, !1 = $words, !2 = $prev, !3 = $i, !4 = $char
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   18     1        ASSIGN                                                   !1, <array>
   19     2        ASSIGN                                                   !2, ''
   20     3        ASSIGN                                                   !3, 0
          4      > JMP                                                      ->20
   21     5    >   FETCH_DIM_R                                      ~8      !0, !3
          6        ASSIGN                                                   !4, ~8
   22     7        NOP                                                      
          8        FAST_CONCAT                                      ~10     !4, '+'
          9        INIT_FCALL                                               'ctype_upper'
         10        SEND_VAR                                                 !4
         11        DO_ICALL                                         $11     
         12      > JMPZ                                                     $11, ->15
         13    >   QM_ASSIGN                                        ~12     'true'
         14      > JMP                                                      ->16
         15    >   QM_ASSIGN                                        ~12     'false'
         16    >   CONCAT                                           ~13     ~10, ~12
         17        CONCAT                                           ~14     ~13, '%0A'
         18        ECHO                                                     ~14
   20    19        PRE_INC                                                  !3
         20    >   STRLEN                                           ~16     !0
         21        IS_SMALLER                                               !3, ~16
         22      > JMPNZ                                                    ~17, ->5
   24    23    >   INIT_FCALL                                               'strtolower'
         24        INIT_FCALL                                               'implode'
         25        SEND_VAL                                                 '_'
         26        SEND_VAR                                                 !1
         27        DO_ICALL                                         $18     
         28        SEND_VAR                                                 $18
         29        DO_ICALL                                         $19     
         30      > RETURN                                                   $19
   25    31*     > RETURN                                                   null

End of function convert_case2

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.71 ms | 1403 KiB | 25 Q