3v4l.org

run code in 500+ PHP versions simultaneously
<?php $palettesString = 'someField;0'; $aPalettesArray = trimExplode(';', $palettesString); $aPalettesArray = [ 'fieldName' => $aPalettesArray[0], 'fieldLabel' => $aPalettesArray[1] ?: null, ]; var_dump($aPalettesArray['fieldLabel']); var_dump(!empty($aPalettesArray['fieldLabel'])); $bPalettesArray = trimExplode(';', $palettesString); $bPalettesArray = [ 'fieldName' => $bPalettesArray[0], 'fieldLabel' => $bPalettesArray[1] ?? null, ]; var_dump($bPalettesArray['fieldLabel']); var_dump(!empty($bPalettesArray['fieldLabel'])); function trimExplode($delim, $string, $removeEmptyValues = false, $limit = 0) { $result = explode($delim, $string) ?: []; if ($removeEmptyValues) { $temp = []; foreach ($result as $value) { if (trim($value) !== '') { $temp[] = $value; } } $result = $temp; } if ($limit > 0 && count($result) > $limit) { $lastElements = array_splice($result, $limit - 1); $result[] = implode($delim, $lastElements); } elseif ($limit < 0) { $result = array_slice($result, 0, $limit); } $result = array_map('trim', $result); return $result; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2J46l
function name:  (null)
number of ops:  44
compiled vars:  !0 = $palettesString, !1 = $aPalettesArray, !2 = $bPalettesArray
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, 'someField%3B0'
    6     1        INIT_FCALL_BY_NAME                                           'trimExplode'
          2        SEND_VAL_EX                                                  '%3B'
          3        SEND_VAR_EX                                                  !0
          4        DO_FCALL                                          0  $4      
          5        ASSIGN                                                       !1, $4
    8     6        FETCH_DIM_R                                          ~6      !1, 0
          7        INIT_ARRAY                                           ~7      ~6, 'fieldName'
    9     8        FETCH_DIM_R                                          ~8      !1, 1
          9        JMP_SET                                              ~9      ~8, ->11
    8    10        QM_ASSIGN                                            ~9      null
         11        ADD_ARRAY_ELEMENT                                    ~7      ~9, 'fieldLabel'
    7    12        ASSIGN                                                       !1, ~7
   12    13        INIT_FCALL                                                   'var_dump'
         14        FETCH_DIM_R                                          ~11     !1, 'fieldLabel'
         15        SEND_VAL                                                     ~11
         16        DO_ICALL                                                     
   13    17        INIT_FCALL                                                   'var_dump'
         18        ISSET_ISEMPTY_DIM_OBJ                             1  ~13     !1, 'fieldLabel'
         19        BOOL_NOT                                             ~14     ~13
         20        SEND_VAL                                                     ~14
         21        DO_ICALL                                                     
   16    22        INIT_FCALL_BY_NAME                                           'trimExplode'
         23        SEND_VAL_EX                                                  '%3B'
         24        SEND_VAR_EX                                                  !0
         25        DO_FCALL                                          0  $16     
         26        ASSIGN                                                       !2, $16
   18    27        FETCH_DIM_R                                          ~18     !2, 0
         28        INIT_ARRAY                                           ~19     ~18, 'fieldName'
   19    29        FETCH_DIM_IS                                         ~20     !2, 1
         30        COALESCE                                             ~21     ~20
   18    31        QM_ASSIGN                                            ~21     null
         32        ADD_ARRAY_ELEMENT                                    ~19     ~21, 'fieldLabel'
   17    33        ASSIGN                                                       !2, ~19
   23    34        INIT_FCALL                                                   'var_dump'
         35        FETCH_DIM_R                                          ~23     !2, 'fieldLabel'
         36        SEND_VAL                                                     ~23
         37        DO_ICALL                                                     
   24    38        INIT_FCALL                                                   'var_dump'
         39        ISSET_ISEMPTY_DIM_OBJ                             1  ~25     !2, 'fieldLabel'
         40        BOOL_NOT                                             ~26     ~25
         41        SEND_VAL                                                     ~26
         42        DO_ICALL                                                     
   48    43      > RETURN                                                       1

Function trimexplode:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 23
Branch analysis from position: 12
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
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 20
Branch analysis from position: 21
2 jumps found. (Code = 46) Position 1 = 25, Position 2 = 28
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 39
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 47
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
Branch analysis from position: 28
Branch analysis from position: 21
Branch analysis from position: 23
filename:       /in/2J46l
function name:  trimExplode
number of ops:  54
compiled vars:  !0 = $delim, !1 = $string, !2 = $removeEmptyValues, !3 = $limit, !4 = $result, !5 = $temp, !6 = $value, !7 = $lastElements
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   28     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV_INIT                                            !2      <false>
          3        RECV_INIT                                            !3      0
   30     4        INIT_FCALL                                                   'explode'
          5        SEND_VAR                                                     !0
          6        SEND_VAR                                                     !1
          7        DO_ICALL                                             $8      
          8        JMP_SET                                              ~9      $8, ->10
          9        QM_ASSIGN                                            ~9      <array>
         10        ASSIGN                                                       !4, ~9
   31    11      > JMPZ                                                         !2, ->23
   32    12    >   ASSIGN                                                       !5, <array>
   33    13      > FE_RESET_R                                           $12     !4, ->21
         14    > > FE_FETCH_R                                                   $12, !6, ->21
   34    15    >   FRAMELESS_ICALL_1                trim                ~13     !6
         16        IS_NOT_IDENTICAL                                             ~13, ''
         17      > JMPZ                                                         ~14, ->20
   35    18    >   ASSIGN_DIM                                                   !5
         19        OP_DATA                                                      !6
   33    20    > > JMP                                                          ->14
         21    >   FE_FREE                                                      $12
   38    22        ASSIGN                                                       !4, !5
   40    23    >   IS_SMALLER                                           ~17     0, !3
         24      > JMPZ_EX                                              ~17     ~17, ->28
         25    >   COUNT                                                ~18     !4
         26        IS_SMALLER                                           ~19     !3, ~18
         27        BOOL                                                 ~17     ~19
         28    > > JMPZ                                                         ~17, ->39
   41    29    >   INIT_FCALL                                                   'array_splice'
         30        SEND_REF                                                     !4
         31        SUB                                                  ~20     !3, 1
         32        SEND_VAL                                                     ~20
         33        DO_ICALL                                             $21     
         34        ASSIGN                                                       !7, $21
   42    35        FRAMELESS_ICALL_2                implode             ~24     !0, !7
         36        ASSIGN_DIM                                                   !4
         37        OP_DATA                                                      ~24
   40    38      > JMP                                                          ->47
   43    39    >   IS_SMALLER                                                   !3, 0
         40      > JMPZ                                                         ~25, ->47
   44    41    >   INIT_FCALL                                                   'array_slice'
         42        SEND_VAR                                                     !4
         43        SEND_VAL                                                     0
         44        SEND_VAR                                                     !3
         45        DO_ICALL                                             $26     
         46        ASSIGN                                                       !4, $26
   46    47    >   INIT_FCALL                                                   'array_map'
         48        SEND_VAL                                                     'trim'
         49        SEND_VAR                                                     !4
         50        DO_ICALL                                             $28     
         51        ASSIGN                                                       !4, $28
   47    52      > RETURN                                                       !4
   48    53*     > RETURN                                                       null

End of function trimexplode

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
150.74 ms | 508 KiB | 18 Q