3v4l.org

run code in 300+ PHP versions simultaneously
<?php function hasColor(Array $a,$color){ foreach($a as $k=>$v){ if($v['color']===$color){ return true; } } return false; } function checkColors(Array &$a){ foreach($a as $k=>&$v){ switch($v['color']){ case 'blue': $appendColor = 'pink'; break; case 'green': $appendColor = 'blue'; break; case 'pink': $appendColor = 'green'; break; } if(hasColor($a,$appendColor)){ continue; } $a[] = ['color'=>$appendColor]; return checkColors($a); } } $colors = [ [ 'color'=>'blue' ] ]; checkColors($colors); var_dump($colors);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8vujf
function name:  (null)
number of ops:  8
compiled vars:  !0 = $colors
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   ASSIGN                                                   !0, <array>
   53     1        INIT_FCALL                                               'checkcolors'
          2        SEND_REF                                                 !0
          3        DO_FCALL                                      0          
   55     4        INIT_FCALL                                               'var_dump'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function hascolor:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 11
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/8vujf
function name:  hasColor
number of ops:  14
compiled vars:  !0 = $a, !1 = $color, !2 = $v, !3 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2      > FE_RESET_R                                       $4      !0, ->11
          3    > > FE_FETCH_R                                       ~5      $4, !2, ->11
          4    >   ASSIGN                                                   !3, ~5
    6     5        FETCH_DIM_R                                      ~7      !2, 'color'
          6        IS_IDENTICAL                                             !1, ~7
          7      > JMPZ                                                     ~8, ->10
    7     8    >   FE_FREE                                                  $4
          9      > RETURN                                                   <true>
    5    10    > > JMP                                                      ->3
         11    >   FE_FREE                                                  $4
   11    12      > RETURN                                                   <false>
   13    13*     > RETURN                                                   null

End of function hascolor

Function checkcolors:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 2, Position 2 = 35
Branch analysis from position: 2
2 jumps found. (Code = 126) Position 1 = 3, Position 2 = 35
Branch analysis from position: 3
5 jumps found. (Code = 188) Position 1 = 13, Position 2 = 15, Position 3 = 17, Position 4 = 19, Position 5 = 6
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 26
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 19
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 8, Position 2 = 13
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 10, Position 2 = 15
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 17
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 17
Branch analysis from position: 15
Branch analysis from position: 13
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
filename:       /in/8vujf
function name:  checkColors
number of ops:  37
compiled vars:  !0 = $a, !1 = $v, !2 = $k, !3 = $appendColor
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   17     1      > FE_RESET_RW                                      $4      !0, ->35
          2    > > FE_FETCH_RW                                      ~5      $4, !1, ->35
          3    >   ASSIGN                                                   !2, ~5
   19     4        FETCH_DIM_R                                      ~7      !1, 'color'
          5      > SWITCH_STRING                                            ~7, [ 'blue':->13, 'green':->15, 'pink':->17, ], ->19
   21     6    >   CASE                                                     ~7, 'blue'
          7      > JMPNZ                                                    ~8, ->13
   25     8    >   CASE                                                     ~7, 'green'
          9      > JMPNZ                                                    ~8, ->15
   29    10    >   CASE                                                     ~7, 'pink'
         11      > JMPNZ                                                    ~8, ->17
         12    > > JMP                                                      ->19
   22    13    >   ASSIGN                                                   !3, 'pink'
   23    14      > JMP                                                      ->19
   26    15    >   ASSIGN                                                   !3, 'blue'
   27    16      > JMP                                                      ->19
   30    17    >   ASSIGN                                                   !3, 'green'
   31    18      > JMP                                                      ->19
         19    >   FREE                                                     ~7
   35    20        INIT_FCALL                                               'hascolor'
         21        SEND_VAR                                                 !0
         22        SEND_VAR                                                 !3
         23        DO_FCALL                                      0  $12     
         24      > JMPZ                                                     $12, ->26
   36    25    > > JMP                                                      ->2
   39    26    >   INIT_ARRAY                                       ~14     !3, 'color'
         27        ASSIGN_DIM                                               !0
         28        OP_DATA                                                  ~14
   41    29        INIT_FCALL_BY_NAME                                       'checkColors'
         30        SEND_VAR_EX                                              !0
         31        DO_FCALL                                      0  $15     
         32        FE_FREE                                                  $4
         33      > RETURN                                                   $15
   17    34*       JMP                                                      ->2
         35    >   FE_FREE                                                  $4
   45    36      > RETURN                                                   null

End of function checkcolors

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.36 ms | 1407 KiB | 17 Q