3v4l.org

run code in 300+ PHP versions simultaneously
<?php if(!function_exists('is_assoc')){ function is_assoc($array) { return (bool)count(array_filter(array_keys($array), 'is_string')); } } /** * getCols * * Takes an array of associative arrays and combines them to get * the columns * * @author Joe Richardson * @access public * @return object Instance of DB or Null */ function getCols(array $data, $col = null) { if(is_assoc($data)){ $d = $data; }else{ $d = (array)call_user_func_array('array_merge_recursive',$data); } return ($col === null)?$d:$d[$col]; } $a = array( array( 'id' => 1 , 'name' => 'foo' , 'date' => date('m-d-Y') ) , array( 'id' => 2 , 'name' => 'bar' , 'date' => date('m-d-Y') ) , array( 'id' => 3 , 'name' => 'george' , 'date' => date('m-d-Y') ) , array( 'id' => 4 , 'name' => 'burdell' , 'date' => date('m-d-Y') ) ); $b = getCols($a, 'name'); var_dump($b);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
filename:       /in/6vbb7
function name:  (null)
number of ops:  44
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   INIT_FCALL                                               'function_exists'
          1        SEND_VAL                                                 'is_assoc'
          2        DO_ICALL                                         $2      
          3        BOOL_NOT                                         ~3      $2
          4      > JMPZ                                                     ~3, ->6
    5     5    >   DECLARE_FUNCTION                                         'is_assoc'
   38     6    >   INIT_ARRAY                                       ~4      1, 'id'
   39     7        ADD_ARRAY_ELEMENT                                ~4      'foo', 'name'
   40     8        INIT_FCALL                                               'date'
          9        SEND_VAL                                                 'm-d-Y'
         10        DO_ICALL                                         $5      
         11        ADD_ARRAY_ELEMENT                                ~4      $5, 'date'
         12        INIT_ARRAY                                       ~6      ~4
   42    13        INIT_ARRAY                                       ~7      2, 'id'
   43    14        ADD_ARRAY_ELEMENT                                ~7      'bar', 'name'
   44    15        INIT_FCALL                                               'date'
         16        SEND_VAL                                                 'm-d-Y'
         17        DO_ICALL                                         $8      
         18        ADD_ARRAY_ELEMENT                                ~7      $8, 'date'
         19        ADD_ARRAY_ELEMENT                                ~6      ~7
   46    20        INIT_ARRAY                                       ~9      3, 'id'
   47    21        ADD_ARRAY_ELEMENT                                ~9      'george', 'name'
   48    22        INIT_FCALL                                               'date'
         23        SEND_VAL                                                 'm-d-Y'
         24        DO_ICALL                                         $10     
         25        ADD_ARRAY_ELEMENT                                ~9      $10, 'date'
         26        ADD_ARRAY_ELEMENT                                ~6      ~9
   50    27        INIT_ARRAY                                       ~11     4, 'id'
   51    28        ADD_ARRAY_ELEMENT                                ~11     'burdell', 'name'
   52    29        INIT_FCALL                                               'date'
         30        SEND_VAL                                                 'm-d-Y'
         31        DO_ICALL                                         $12     
         32        ADD_ARRAY_ELEMENT                                ~11     $12, 'date'
         33        ADD_ARRAY_ELEMENT                                ~6      ~11
   36    34        ASSIGN                                                   !0, ~6
   57    35        INIT_FCALL                                               'getcols'
         36        SEND_VAR                                                 !0
         37        SEND_VAL                                                 'name'
         38        DO_FCALL                                      0  $14     
         39        ASSIGN                                                   !1, $14
   59    40        INIT_FCALL                                               'var_dump'
         41        SEND_VAR                                                 !1
         42        DO_ICALL                                                 
         43      > RETURN                                                   1

Function %00is_assoc%2Fin%2F6vbb7%3A5%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6vbb7
function name:  is_assoc
number of ops:  12
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    6     1        INIT_FCALL                                               'array_filter'
          2        INIT_FCALL                                               'array_keys'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5        SEND_VAR                                                 $1
          6        SEND_VAL                                                 'is_string'
          7        DO_ICALL                                         $2      
          8        COUNT                                            ~3      $2
          9        BOOL                                             ~4      ~3
         10      > RETURN                                                   ~4
    7    11*     > RETURN                                                   null

End of function %00is_assoc%2Fin%2F6vbb7%3A5%240

Function getcols:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
Branch analysis from position: 18
filename:       /in/6vbb7
function name:  getCols
number of ops:  22
compiled vars:  !0 = $data, !1 = $col, !2 = $d
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
   24     2        INIT_FCALL_BY_NAME                                       'is_assoc'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $3      
          5      > JMPZ                                                     $3, ->8
   25     6    >   ASSIGN                                                   !2, !0
          7      > JMP                                                      ->14
   27     8    >   INIT_FCALL                                               'array_merge_recursive'
          9        SEND_ARRAY                                               !0
         10        CHECK_UNDEF_ARGS                                         
         11        DO_FCALL                                      0  $5      
         12        CAST                                          7  ~6      $5
         13        ASSIGN                                                   !2, ~6
   30    14    >   TYPE_CHECK                                    2          !1
         15      > JMPZ                                                     ~8, ->18
         16    >   QM_ASSIGN                                        ~9      !2
         17      > JMP                                                      ->20
         18    >   FETCH_DIM_R                                      ~10     !2, !1
         19        QM_ASSIGN                                        ~9      ~10
         20    > > RETURN                                                   ~9
   31    21*     > RETURN                                                   null

End of function getcols

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.88 ms | 1398 KiB | 26 Q