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(); switch (func_num_args()) { case 0: trigger_error('array_column() expects at least 2 parameters, 0 given', E_USER_WARNING); return null; case 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, ), ), null ) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OG9Rd
function name:  (null)
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   76     0  E >   INIT_FCALL                                               'var_dump'
   77     1        INIT_FCALL                                               'array_column1'
   80     2        SEND_VAL                                                 <array>
   84     3        SEND_VAL                                                 null
          4        DO_FCALL                                      0  $0      
          5        SEND_VAR                                                 $0
          6        DO_ICALL                                                 
   86     7      > RETURN                                                   1

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

End of function array_column1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
205.11 ms | 1414 KiB | 20 Q