3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = [ 'labels' => ['Manager','Director'], 'dataset' => [3, 2] ]; $arr = array_combine(['labels','dataset'], array_map(null, $arr)); function setData($userType, $array) { if(!in_array($userType, $array['labels'])){ array_push($array['labels'], $userType); array_push($array['dataset'], 0); } return $array; } foreach(['Manager', 'Trainee', 'Director'] as $type) { $arr = setData($type, $arr); } print_r($arr); die();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 18
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 18
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 18
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 18
filename:       /in/UbiXn
function name:  (null)
number of ops:  24
compiled vars:  !0 = $arr, !1 = $type
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    7     1        INIT_FCALL                                               'array_combine'
          2        SEND_VAL                                                 <array>
          3        INIT_FCALL                                               'array_map'
          4        SEND_VAL                                                 null
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $3      
          7        SEND_VAR                                                 $3
          8        DO_ICALL                                         $4      
          9        ASSIGN                                                   !0, $4
   16    10      > FE_RESET_R                                       $6      <array>, ->18
         11    > > FE_FETCH_R                                               $6, !1, ->18
   17    12    >   INIT_FCALL                                               'setdata'
         13        SEND_VAR                                                 !1
         14        SEND_VAR                                                 !0
         15        DO_FCALL                                      0  $7      
         16        ASSIGN                                                   !0, $7
   16    17      > JMP                                                      ->11
         18    >   FE_FREE                                                  $6
   20    19        INIT_FCALL                                               'print_r'
         20        SEND_VAR                                                 !0
         21        DO_ICALL                                                 
   21    22      > EXIT                                                     
         23*     > RETURN                                                   1

Function setdata:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 19
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/UbiXn
function name:  setData
number of ops:  21
compiled vars:  !0 = $userType, !1 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    9     2        INIT_FCALL                                               'in_array'
          3        SEND_VAR                                                 !0
          4        FETCH_DIM_R                                      ~2      !1, 'labels'
          5        SEND_VAL                                                 ~2
          6        DO_ICALL                                         $3      
          7        BOOL_NOT                                         ~4      $3
          8      > JMPZ                                                     ~4, ->19
   10     9    >   INIT_FCALL                                               'array_push'
         10        FETCH_DIM_W                                      $5      !1, 'labels'
         11        SEND_REF                                                 $5
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                                 
   11    14        INIT_FCALL                                               'array_push'
         15        FETCH_DIM_W                                      $7      !1, 'dataset'
         16        SEND_REF                                                 $7
         17        SEND_VAL                                                 0
         18        DO_ICALL                                                 
   14    19    > > RETURN                                                   !1
   15    20*     > RETURN                                                   null

End of function setdata

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.39 ms | 1022 KiB | 19 Q