3v4l.org

run code in 300+ PHP versions simultaneously
<?php if (!function_exists('array_column')) { function array_column($input, $column_key, $index_key = null) { if ($index_key !== null) { // Collect the keys $keys = array(); $i = 0; // Counter for numerical keys when key does not exist foreach ($input as $row) { if (array_key_exists($index_key, $row)) { // Update counter for numerical keys if (is_numeric($row[$index_key]) || is_bool($row[$index_key])) { $i = max($i, (int) $row[$index_key] + 1); } // Get the key from a single column of the array $keys[] = $row[$index_key]; } else { // The key does not exist, use numerical indexing $keys[] = $i++; } } } if ($column_key !== null) { // Collect the values $values = array(); $i = 0; // Counter for removing keys foreach ($input as $row) { if (array_key_exists($column_key, $row)) { // Get the values from a single column of the input array $values[] = $row[$column_key]; $i++; } elseif (isset($keys)) { // Values does not exist, also drop the key for it array_splice($keys, $i, 1); } } } else { // Get the full arrays $values = array_values($input); } if ($index_key !== null) { return array_combine($keys, $values); } return $values; } echo "Custom array_column()"; } $records = array( array( 'id' => 2135, 'first_name' => 'John', 'last_name' => 'Doe', ), array( 'id' => 3245, 'first_name' => 'Sally', 'last_name' => 'Smith', ), array( 'id' => 5342, 'first_name' => 'Jane', 'last_name' => 'Jones', ), array( 'id' => 5623, 'first_name' => 'Peter', 'last_name' => 'Doe', ) ); $start = microtime(true); for ($i=0;$i<9999;$i++) { array_column($records, 'first_name'); } $end = microtime(true); echo $end-$start."\n";
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 14
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 21, Position 2 = 14
Branch analysis from position: 21
Branch analysis from position: 14
Branch analysis from position: 7
filename:       /in/iKCsh
function name:  (null)
number of ops:  29
compiled vars:  !0 = $records, !1 = $start, !2 = $i, !3 = $end
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   INIT_FCALL                                               'function_exists'
          1        SEND_VAL                                                 'array_column'
          2        DO_ICALL                                         $4      
          3        BOOL_NOT                                         ~5      $4
          4      > JMPZ                                                     ~5, ->7
    3     5    >   DECLARE_FUNCTION                                         'array_column'
   52     6        ECHO                                                     'Custom+array_column%28%29'
   56     7    >   ASSIGN                                                   !0, <array>
   80     8        INIT_FCALL                                               'microtime'
          9        SEND_VAL                                                 <true>
         10        DO_ICALL                                         $7      
         11        ASSIGN                                                   !1, $7
   81    12        ASSIGN                                                   !2, 0
         13      > JMP                                                      ->19
   82    14    >   INIT_FCALL                                               'array_column'
         15        SEND_VAR                                                 !0
         16        SEND_VAL                                                 'first_name'
         17        DO_ICALL                                                 
   81    18        PRE_INC                                                  !2
         19    >   IS_SMALLER                                               !2, 9999
         20      > JMPNZ                                                    ~12, ->14
   84    21    >   INIT_FCALL                                               'microtime'
         22        SEND_VAL                                                 <true>
         23        DO_ICALL                                         $13     
         24        ASSIGN                                                   !3, $13
   86    25        SUB                                              ~15     !3, !1
         26        CONCAT                                           ~16     ~15, '%0A'
         27        ECHO                                                     ~16
         28      > RETURN                                                   1

Function %00array_column%2Fin%2FiKCsh%3A3%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 37
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 36
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 36
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 32
Branch analysis from position: 11
2 jumps found. (Code = 47) Position 1 = 16, Position 2 = 19
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 28
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 28
Branch analysis from position: 19
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 60
Branch analysis from position: 39
2 jumps found. (Code = 77) Position 1 = 42, Position 2 = 58
Branch analysis from position: 42
2 jumps found. (Code = 78) Position 1 = 43, Position 2 = 58
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 50
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
Branch analysis from position: 50
2 jumps found. (Code = 43) Position 1 = 52, Position 2 = 57
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
Branch analysis from position: 57
Branch analysis from position: 58
1 jumps found. (Code = 42) Position 1 = 64
Branch analysis from position: 64
2 jumps found. (Code = 43) Position 1 = 66, Position 2 = 71
Branch analysis from position: 66
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 71
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 58
Branch analysis from position: 60
2 jumps found. (Code = 43) Position 1 = 66, Position 2 = 71
Branch analysis from position: 66
Branch analysis from position: 71
Branch analysis from position: 36
Branch analysis from position: 37
filename:       /in/iKCsh
function name:  array_column
number of ops:  73
compiled vars:  !0 = $input, !1 = $column_key, !2 = $index_key, !3 = $keys, !4 = $i, !5 = $row, !6 = $values
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      null
    5     3        TYPE_CHECK                                  1020          !2
          4      > JMPZ                                                     ~7, ->37
    7     5    >   ASSIGN                                                   !3, <array>
    8     6        ASSIGN                                                   !4, 0
   10     7      > FE_RESET_R                                       $10     !0, ->36
          8    > > FE_FETCH_R                                               $10, !5, ->36
   11     9    >   ARRAY_KEY_EXISTS                                         !2, !5
         10      > JMPZ                                                     ~11, ->32
   13    11    >   INIT_FCALL                                               'is_numeric'
         12        FETCH_DIM_R                                      ~12     !5, !2
         13        SEND_VAL                                                 ~12
         14        DO_ICALL                                         $13     
         15      > JMPNZ_EX                                         ~14     $13, ->19
         16    >   FETCH_DIM_R                                      ~15     !5, !2
         17        TYPE_CHECK                                   12  ~16     ~15
         18        BOOL                                             ~14     ~16
         19    > > JMPZ                                                     ~14, ->28
   14    20    >   INIT_FCALL                                               'max'
         21        SEND_VAR                                                 !4
         22        FETCH_DIM_R                                      ~17     !5, !2
         23        CAST                                          4  ~18     ~17
         24        ADD                                              ~19     ~18, 1
         25        SEND_VAL                                                 ~19
         26        DO_ICALL                                         $20     
         27        ASSIGN                                                   !4, $20
   18    28    >   FETCH_DIM_R                                      ~23     !5, !2
         29        ASSIGN_DIM                                               !3
         30        OP_DATA                                                  ~23
         31      > JMP                                                      ->35
   21    32    >   POST_INC                                         ~25     !4
         33        ASSIGN_DIM                                               !3
         34        OP_DATA                                                  ~25
   10    35    > > JMP                                                      ->8
         36    >   FE_FREE                                                  $10
   26    37    >   TYPE_CHECK                                  1020          !1
         38      > JMPZ                                                     ~26, ->60
   28    39    >   ASSIGN                                                   !6, <array>
   29    40        ASSIGN                                                   !4, 0
   31    41      > FE_RESET_R                                       $29     !0, ->58
         42    > > FE_FETCH_R                                               $29, !5, ->58
   32    43    >   ARRAY_KEY_EXISTS                                         !1, !5
         44      > JMPZ                                                     ~30, ->50
   34    45    >   FETCH_DIM_R                                      ~32     !5, !1
         46        ASSIGN_DIM                                               !6
         47        OP_DATA                                                  ~32
   35    48        PRE_INC                                                  !4
         49      > JMP                                                      ->57
   36    50    >   ISSET_ISEMPTY_CV                                         !3
         51      > JMPZ                                                     ~34, ->57
   38    52    >   INIT_FCALL                                               'array_splice'
         53        SEND_REF                                                 !3
         54        SEND_VAR                                                 !4
         55        SEND_VAL                                                 1
         56        DO_ICALL                                                 
   31    57    > > JMP                                                      ->42
         58    >   FE_FREE                                                  $29
         59      > JMP                                                      ->64
   43    60    >   INIT_FCALL                                               'array_values'
         61        SEND_VAR                                                 !0
         62        DO_ICALL                                         $36     
         63        ASSIGN                                                   !6, $36
   46    64    >   TYPE_CHECK                                  1020          !2
         65      > JMPZ                                                     ~38, ->71
   47    66    >   INIT_FCALL                                               'array_combine'
         67        SEND_VAR                                                 !3
         68        SEND_VAR                                                 !6
         69        DO_ICALL                                         $39     
         70      > RETURN                                                   $39
   50    71    > > RETURN                                                   !6
   51    72*     > RETURN                                                   null

End of function %00array_column%2Fin%2FiKCsh%3A3%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.97 ms | 1404 KiB | 29 Q