3v4l.org

run code in 300+ PHP versions simultaneously
<?php function array_column1($input = null, $columnKey = null, $indexKey = null) { // Using func_get_args() in order to check for proper number of // parameters and trigger errors exactly as the built-in array_column() // does in PHP 5.5. $params = func_get_args(); if (!isset($params[0])) { trigger_error('array_column() expects at least 2 parameters, 0 given', E_USER_WARNING); return null; } elseif (!isset($params[1])) { trigger_error('array_column() expects at least 2 parameters, 1 given', E_USER_WARNING); return null; } if (!is_array($params[0])) { trigger_error('array_column() expects parameter 1 to be array, ' . gettype($params[0]) . ' given', E_USER_WARNING); return null; } if (!is_int($params[1]) && !is_string($params[1]) && !(is_object($params[1]) && method_exists($params[1], '__toString')) ) { trigger_error('array_column(): The column key should be either a string or an integer', E_USER_WARNING); return false; } if (isset($params[2]) && !is_int($params[2]) && !is_string($params[2]) && !(is_object($params[2]) && method_exists($params[2], '__toString')) ) { trigger_error('array_column(): The index key should be either a string or an integer', E_USER_WARNING); return false; } $paramsInput = $params[0]; $paramsColumnKey = (string) $params[1]; $paramsIndexKey = (isset($params[2]) ? (string) $params[2] : null); $resultArray = array(); foreach ($paramsInput as $row) { $key = $value = null; $keySet = $valueSet = false; if ($paramsIndexKey !== null && array_key_exists($paramsIndexKey, $row)) { $keySet = true; $key = $row[$paramsIndexKey]; } if (is_array($row) && array_key_exists($paramsColumnKey, $row)) { $valueSet = true; $value = $row[$paramsColumnKey]; } if ($valueSet) { if ($keySet) { $resultArray[$key] = $value; } else { $resultArray[] = $value; } } } return $resultArray; } var_dump( array_column1( array( array( 'a' => null, 'b' => 16, ), ), 'a' ) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qTJKF
function name:  (null)
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   73     0  E >   INIT_FCALL                                               'var_dump'
   74     1        INIT_FCALL                                               'array_column1'
   77     2        SEND_VAL                                                 <array>
   81     3        SEND_VAL                                                 'a'
          4        DO_FCALL                                      0  $0      
          5        SEND_VAR                                                 $0
          6        DO_ICALL                                                 
   83     7      > RETURN                                                   1

Function array_column1:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 22
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 35
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
2 jumps found. (Code = 46) Position 1 = 39, Position 2 = 43
Branch analysis from position: 39
2 jumps found. (Code = 46) Position 1 = 44, Position 2 = 55
Branch analysis from position: 44
2 jumps found. (Code = 46) Position 1 = 47, Position 2 = 53
Branch analysis from position: 47
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 61
Branch analysis from position: 56
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 61
2 jumps found. (Code = 46) Position 1 = 63, Position 2 = 67
Branch analysis from position: 63
2 jumps found. (Code = 46) Position 1 = 68, Position 2 = 72
Branch analysis from position: 68
2 jumps found. (Code = 46) Position 1 = 73, Position 2 = 84
Branch analysis from position: 73
2 jumps found. (Code = 46) Position 1 = 76, Position 2 = 82
Branch analysis from position: 76
2 jumps found. (Code = 43) Position 1 = 85, Position 2 = 90
Branch analysis from position: 85
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 90
2 jumps found. (Code = 43) Position 1 = 97, Position 2 = 101
Branch analysis from position: 97
1 jumps found. (Code = 42) Position 1 = 102
Branch analysis from position: 102
2 jumps found. (Code = 77) Position 1 = 105, Position 2 = 134
Branch analysis from position: 105
2 jumps found. (Code = 78) Position 1 = 106, Position 2 = 134
Branch analysis from position: 106
2 jumps found. (Code = 46) Position 1 = 112, Position 2 = 114
Branch analysis from position: 112
2 jumps found. (Code = 43) Position 1 = 115, Position 2 = 118
Branch analysis from position: 115
2 jumps found. (Code = 46) Position 1 = 120, Position 2 = 122
Branch analysis from position: 120
2 jumps found. (Code = 43) Position 1 = 123, Position 2 = 126
Branch analysis from position: 123
2 jumps found. (Code = 43) Position 1 = 127, Position 2 = 133
Branch analysis from position: 127
2 jumps found. (Code = 43) Position 1 = 128, Position 2 = 131
Branch analysis from position: 128
1 jumps found. (Code = 42) Position 1 = 133
Branch analysis from position: 133
1 jumps found. (Code = 42) Position 1 = 105
Branch analysis from position: 105
Branch analysis from position: 131
1 jumps found. (Code = 42) Position 1 = 105
Branch analysis from position: 105
Branch analysis from position: 133
Branch analysis from position: 126
Branch analysis from position: 122
Branch analysis from position: 118
Branch analysis from position: 114
Branch analysis from position: 134
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 134
Branch analysis from position: 101
2 jumps found. (Code = 77) Position 1 = 105, Position 2 = 134
Branch analysis from position: 105
Branch analysis from position: 134
Branch analysis from position: 82
Branch analysis from position: 84
Branch analysis from position: 72
Branch analysis from position: 67
Branch analysis from position: 53
Branch analysis from position: 55
Branch analysis from position: 43
filename:       /in/qTJKF
function name:  array_column1
number of ops:  137
compiled vars:  !0 = $input, !1 = $columnKey, !2 = $indexKey, !3 = $params, !4 = $paramsInput, !5 = $paramsColumnKey, !6 = $paramsIndexKey, !7 = $resultArray, !8 = $row, !9 = $key, !10 = $value, !11 = $keySet, !12 = $valueSet
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV_INIT                                        !0      null
          1        RECV_INIT                                        !1      null
          2        RECV_INIT                                        !2      null
    7     3        FUNC_GET_ARGS                                    ~13     
          4        ASSIGN                                                   !3, ~13
    9     5        ISSET_ISEMPTY_DIM_OBJ                         0  ~15     !3, 0
          6        BOOL_NOT                                         ~16     ~15
          7      > JMPZ                                                     ~16, ->14
   10     8    >   INIT_FCALL                                               'trigger_error'
          9        SEND_VAL                                                 'array_column%28%29+expects+at+least+2+parameters%2C+0+given'
         10        SEND_VAL                                                 512
         11        DO_ICALL                                                 
   11    12      > RETURN                                                   null
         13*       JMP                                                      ->22
   12    14    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~18     !3, 1
         15        BOOL_NOT                                         ~19     ~18
         16      > JMPZ                                                     ~19, ->22
   13    17    >   INIT_FCALL                                               'trigger_error'
         18        SEND_VAL                                                 'array_column%28%29+expects+at+least+2+parameters%2C+1+given'
         19        SEND_VAL                                                 512
         20        DO_ICALL                                                 
   14    21      > RETURN                                                   null
   17    22    >   FETCH_DIM_R                                      ~21     !3, 0
         23        TYPE_CHECK                                  128  ~22     ~21
         24        BOOL_NOT                                         ~23     ~22
         25      > JMPZ                                                     ~23, ->35
   18    26    >   INIT_FCALL                                               'trigger_error'
         27        FETCH_DIM_R                                      ~24     !3, 0
         28        GET_TYPE                                         ~25     ~24
         29        CONCAT                                           ~26     'array_column%28%29+expects+parameter+1+to+be+array%2C+', ~25
         30        CONCAT                                           ~27     ~26, '+given'
         31        SEND_VAL                                                 ~27
         32        SEND_VAL                                                 512
         33        DO_ICALL                                                 
   19    34      > RETURN                                                   null
   22    35    >   FETCH_DIM_R                                      ~29     !3, 1
         36        TYPE_CHECK                                   16  ~30     ~29
         37        BOOL_NOT                                         ~31     ~30
         38      > JMPZ_EX                                          ~31     ~31, ->43
   23    39    >   FETCH_DIM_R                                      ~32     !3, 1
         40        TYPE_CHECK                                   64  ~33     ~32
         41        BOOL_NOT                                         ~34     ~33
         42        BOOL                                             ~31     ~34
         43    > > JMPZ_EX                                          ~31     ~31, ->55
   24    44    >   FETCH_DIM_R                                      ~35     !3, 1
         45        TYPE_CHECK                                  256  ~36     ~35
         46      > JMPZ_EX                                          ~36     ~36, ->53
         47    >   INIT_FCALL                                               'method_exists'
         48        FETCH_DIM_R                                      ~37     !3, 1
         49        SEND_VAL                                                 ~37
         50        SEND_VAL                                                 '__toString'
         51        DO_ICALL                                         $38     
         52        BOOL                                             ~36     $38
         53    >   BOOL_NOT                                         ~39     ~36
         54        BOOL                                             ~31     ~39
         55    > > JMPZ                                                     ~31, ->61
   26    56    >   INIT_FCALL                                               'trigger_error'
         57        SEND_VAL                                                 'array_column%28%29%3A+The+column+key+should+be+either+a+string+or+an+integer'
         58        SEND_VAL                                                 512
         59        DO_ICALL                                                 
   27    60      > RETURN                                                   <false>
   30    61    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~41     !3, 2
         62      > JMPZ_EX                                          ~41     ~41, ->67
   31    63    >   FETCH_DIM_R                                      ~42     !3, 2
         64        TYPE_CHECK                                   16  ~43     ~42
         65        BOOL_NOT                                         ~44     ~43
         66        BOOL                                             ~41     ~44
         67    > > JMPZ_EX                                          ~41     ~41, ->72
   32    68    >   FETCH_DIM_R                                      ~45     !3, 2
         69        TYPE_CHECK                                   64  ~46     ~45
         70        BOOL_NOT                                         ~47     ~46
         71        BOOL                                             ~41     ~47
         72    > > JMPZ_EX                                          ~41     ~41, ->84
   33    73    >   FETCH_DIM_R                                      ~48     !3, 2
         74        TYPE_CHECK                                  256  ~49     ~48
         75      > JMPZ_EX                                          ~49     ~49, ->82
         76    >   INIT_FCALL                                               'method_exists'
         77        FETCH_DIM_R                                      ~50     !3, 2
         78        SEND_VAL                                                 ~50
         79        SEND_VAL                                                 '__toString'
         80        DO_ICALL                                         $51     
         81        BOOL                                             ~49     $51
         82    >   BOOL_NOT                                         ~52     ~49
         83        BOOL                                             ~41     ~52
         84    > > JMPZ                                                     ~41, ->90
   35    85    >   INIT_FCALL                                               'trigger_error'
         86        SEND_VAL                                                 'array_column%28%29%3A+The+index+key+should+be+either+a+string+or+an+integer'
         87        SEND_VAL                                                 512
         88        DO_ICALL                                                 
   36    89      > RETURN                                                   <false>
   39    90    >   FETCH_DIM_R                                      ~54     !3, 0
         91        ASSIGN                                                   !4, ~54
   40    92        FETCH_DIM_R                                      ~56     !3, 1
         93        CAST                                          6  ~57     ~56
         94        ASSIGN                                                   !5, ~57
   41    95        ISSET_ISEMPTY_DIM_OBJ                         0          !3, 2
         96      > JMPZ                                                     ~59, ->101
         97    >   FETCH_DIM_R                                      ~60     !3, 2
         98        CAST                                          6  ~61     ~60
         99        QM_ASSIGN                                        ~62     ~61
        100      > JMP                                                      ->102
        101    >   QM_ASSIGN                                        ~62     null
        102    >   ASSIGN                                                   !6, ~62
   42   103        ASSIGN                                                   !7, <array>
   44   104      > FE_RESET_R                                       $65     !4, ->134
        105    > > FE_FETCH_R                                               $65, !8, ->134
   46   106    >   ASSIGN                                           ~66     !10, null
        107        ASSIGN                                                   !9, ~66
   47   108        ASSIGN                                           ~68     !12, <false>
        109        ASSIGN                                                   !11, ~68
   49   110        TYPE_CHECK                                  1020  ~70     !6
        111      > JMPZ_EX                                          ~70     ~70, ->114
        112    >   ARRAY_KEY_EXISTS                                 ~71     !6, !8
        113        BOOL                                             ~70     ~71
        114    > > JMPZ                                                     ~70, ->118
   50   115    >   ASSIGN                                                   !11, <true>
   51   116        FETCH_DIM_R                                      ~73     !8, !6
        117        ASSIGN                                                   !9, ~73
   54   118    >   TYPE_CHECK                                  128  ~75     !8
        119      > JMPZ_EX                                          ~75     ~75, ->122
        120    >   ARRAY_KEY_EXISTS                                 ~76     !5, !8
        121        BOOL                                             ~75     ~76
        122    > > JMPZ                                                     ~75, ->126
   55   123    >   ASSIGN                                                   !12, <true>
   56   124        FETCH_DIM_R                                      ~78     !8, !5
        125        ASSIGN                                                   !10, ~78
   59   126    > > JMPZ                                                     !12, ->133
   60   127    > > JMPZ                                                     !11, ->131
   61   128    >   ASSIGN_DIM                                               !7, !9
        129        OP_DATA                                                  !10
        130      > JMP                                                      ->133
   63   131    >   ASSIGN_DIM                                               !7
        132        OP_DATA                                                  !10
   44   133    > > JMP                                                      ->105
        134    >   FE_FREE                                                  $65
   69   135      > RETURN                                                   !7
   70   136*     > RETURN                                                   null

End of function array_column1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.78 ms | 1415 KiB | 20 Q