3v4l.org

run code in 300+ PHP versions simultaneously
<?php function reindexArray($array, $column) { return array_combine( array_map(function($x) use ($column) { return $x[$column]; }, $array), $array ); } function arrayJoin($array1, $array2, $column, $default=null) { //in PHP 5.5 it's just array_column() call: $array1 = reindexArray($array1, $column); $array2 = reindexArray($array2, $column); $blank1 = array_combine( array_keys(current($array1)), array_fill(1, count(current($array1)), $default) ); $blank2 = array_combine( array_keys(current($array2)), array_fill(1, count(current($array2)), $default) ); unset($blank1[$column], $blank2[$column]); return array_merge( array_map(function($x) use ($array1, $blank2) { return array_merge($array1[$x], $blank2); }, array_keys(array_diff_key($array1, $array2))), array_map(function($x) use ($array1, $array2) { return array_merge($array1[$x], $array2[$x]); }, array_keys(array_intersect_key($array1, $array2))), array_map(function($x) use ($array2, $blank1) { return array_merge($array2[$x], $blank1); }, array_keys(array_diff_key($array2, $array1))) ); } $array1 = array(); $array1[]=array('subscribers'=>2,'dt_date'=>'2014-02-27'); $array1[]=array('subscribers'=>2,'dt_date'=>'2014-02-25'); $array1[]=array('subscribers'=>1,'dt_date'=>'2014-02-07'); $array2 = array(); $array2[]=array('unsubscribers'=>1,'dt_date'=>'2014-02-27'); $array2[]=array('unsubscribers'=>1,'dt_date'=>'2014-02-01'); var_dump(arrayJoin($array1, $array2, 'dt_date', 0));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lUAeN
function name:  (null)
number of ops:  22
compiled vars:  !0 = $array1, !1 = $array2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   ASSIGN                                                   !0, <array>
   46     1        ASSIGN_DIM                                               !0
          2        OP_DATA                                                  <array>
   47     3        ASSIGN_DIM                                               !0
          4        OP_DATA                                                  <array>
   48     5        ASSIGN_DIM                                               !0
          6        OP_DATA                                                  <array>
   50     7        ASSIGN                                                   !1, <array>
   51     8        ASSIGN_DIM                                               !1
          9        OP_DATA                                                  <array>
   52    10        ASSIGN_DIM                                               !1
         11        OP_DATA                                                  <array>
   55    12        INIT_FCALL                                               'var_dump'
         13        INIT_FCALL                                               'arrayjoin'
         14        SEND_VAR                                                 !0
         15        SEND_VAR                                                 !1
         16        SEND_VAL                                                 'dt_date'
         17        SEND_VAL                                                 0
         18        DO_FCALL                                      0  $9      
         19        SEND_VAR                                                 $9
         20        DO_ICALL                                                 
         21      > RETURN                                                   1

Function reindexarray:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lUAeN
function name:  reindexArray
number of ops:  14
compiled vars:  !0 = $array, !1 = $column
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        INIT_FCALL                                               'array_combine'
    5     3        INIT_FCALL                                               'array_map'
          4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FlUAeN%3A5%240'
          5        BIND_LEXICAL                                             ~2, !1
    8     6        SEND_VAL                                                 ~2
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $3      
          9        SEND_VAR                                                 $3
    9    10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $4      
         12      > RETURN                                                   $4
   11    13*     > RETURN                                                   null

End of function reindexarray

Function %00%7Bclosure%7D%2Fin%2FlUAeN%3A5%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lUAeN
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $x, !1 = $column
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
    7     2        FETCH_DIM_R                                      ~2      !0, !1
          3      > RETURN                                                   ~2
    8     4*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FlUAeN%3A5%240

Function arrayjoin:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lUAeN
function name:  arrayJoin
number of ops:  105
compiled vars:  !0 = $array1, !1 = $array2, !2 = $column, !3 = $default, !4 = $blank1, !5 = $blank2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV_INIT                                        !3      null
   16     4        INIT_FCALL                                               'reindexarray'
          5        SEND_VAR                                                 !0
          6        SEND_VAR                                                 !2
          7        DO_FCALL                                      0  $6      
          8        ASSIGN                                                   !0, $6
   17     9        INIT_FCALL                                               'reindexarray'
         10        SEND_VAR                                                 !1
         11        SEND_VAR                                                 !2
         12        DO_FCALL                                      0  $8      
         13        ASSIGN                                                   !1, $8
   18    14        INIT_FCALL                                               'array_combine'
   19    15        INIT_FCALL                                               'array_keys'
         16        INIT_FCALL                                               'current'
         17        SEND_VAR                                                 !0
         18        DO_ICALL                                         $10     
         19        SEND_VAR                                                 $10
         20        DO_ICALL                                         $11     
         21        SEND_VAR                                                 $11
   20    22        INIT_FCALL                                               'array_fill'
         23        SEND_VAL                                                 1
         24        INIT_FCALL                                               'current'
         25        SEND_VAR                                                 !0
         26        DO_ICALL                                         $12     
         27        COUNT                                            ~13     $12
         28        SEND_VAL                                                 ~13
         29        SEND_VAR                                                 !3
         30        DO_ICALL                                         $14     
         31        SEND_VAR                                                 $14
         32        DO_ICALL                                         $15     
   18    33        ASSIGN                                                   !4, $15
   22    34        INIT_FCALL                                               'array_combine'
   23    35        INIT_FCALL                                               'array_keys'
         36        INIT_FCALL                                               'current'
         37        SEND_VAR                                                 !1
         38        DO_ICALL                                         $17     
         39        SEND_VAR                                                 $17
         40        DO_ICALL                                         $18     
         41        SEND_VAR                                                 $18
   24    42        INIT_FCALL                                               'array_fill'
         43        SEND_VAL                                                 1
         44        INIT_FCALL                                               'current'
         45        SEND_VAR                                                 !1
         46        DO_ICALL                                         $19     
         47        COUNT                                            ~20     $19
         48        SEND_VAL                                                 ~20
         49        SEND_VAR                                                 !3
         50        DO_ICALL                                         $21     
         51        SEND_VAR                                                 $21
         52        DO_ICALL                                         $22     
   22    53        ASSIGN                                                   !5, $22
   26    54        UNSET_DIM                                                !4, !2
         55        UNSET_DIM                                                !5, !2
   28    56        INIT_FCALL                                               'array_merge'
   29    57        INIT_FCALL                                               'array_map'
         58        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FlUAeN%3A29%241'
         59        BIND_LEXICAL                                             ~24, !0
         60        BIND_LEXICAL                                             ~24, !5
   32    61        SEND_VAL                                                 ~24
         62        INIT_FCALL                                               'array_keys'
         63        INIT_FCALL                                               'array_diff_key'
         64        SEND_VAR                                                 !0
         65        SEND_VAR                                                 !1
         66        DO_ICALL                                         $25     
         67        SEND_VAR                                                 $25
         68        DO_ICALL                                         $26     
         69        SEND_VAR                                                 $26
         70        DO_ICALL                                         $27     
         71        SEND_VAR                                                 $27
   33    72        INIT_FCALL                                               'array_map'
         73        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FlUAeN%3A33%242'
         74        BIND_LEXICAL                                             ~28, !0
         75        BIND_LEXICAL                                             ~28, !1
   36    76        SEND_VAL                                                 ~28
         77        INIT_FCALL                                               'array_keys'
         78        INIT_FCALL                                               'array_intersect_key'
         79        SEND_VAR                                                 !0
         80        SEND_VAR                                                 !1
         81        DO_ICALL                                         $29     
         82        SEND_VAR                                                 $29
         83        DO_ICALL                                         $30     
         84        SEND_VAR                                                 $30
         85        DO_ICALL                                         $31     
         86        SEND_VAR                                                 $31
   37    87        INIT_FCALL                                               'array_map'
         88        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FlUAeN%3A37%243'
         89        BIND_LEXICAL                                             ~32, !1
         90        BIND_LEXICAL                                             ~32, !4
   40    91        SEND_VAL                                                 ~32
         92        INIT_FCALL                                               'array_keys'
         93        INIT_FCALL                                               'array_diff_key'
         94        SEND_VAR                                                 !1
         95        SEND_VAR                                                 !0
         96        DO_ICALL                                         $33     
         97        SEND_VAR                                                 $33
         98        DO_ICALL                                         $34     
         99        SEND_VAR                                                 $34
        100        DO_ICALL                                         $35     
        101        SEND_VAR                                                 $35
        102        DO_ICALL                                         $36     
        103      > RETURN                                                   $36
   42   104*     > RETURN                                                   null

End of function arrayjoin

Function %00%7Bclosure%7D%2Fin%2FlUAeN%3A29%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lUAeN
function name:  {closure}
number of ops:  10
compiled vars:  !0 = $x, !1 = $array1, !2 = $blank2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
   31     3        INIT_FCALL                                               'array_merge'
          4        FETCH_DIM_R                                      ~3      !1, !0
          5        SEND_VAL                                                 ~3
          6        SEND_VAR                                                 !2
          7        DO_ICALL                                         $4      
          8      > RETURN                                                   $4
   32     9*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FlUAeN%3A29%241

Function %00%7Bclosure%7D%2Fin%2FlUAeN%3A33%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lUAeN
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $x, !1 = $array1, !2 = $array2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
   35     3        INIT_FCALL                                               'array_merge'
          4        FETCH_DIM_R                                      ~3      !1, !0
          5        SEND_VAL                                                 ~3
          6        FETCH_DIM_R                                      ~4      !2, !0
          7        SEND_VAL                                                 ~4
          8        DO_ICALL                                         $5      
          9      > RETURN                                                   $5
   36    10*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FlUAeN%3A33%242

Function %00%7Bclosure%7D%2Fin%2FlUAeN%3A37%243:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lUAeN
function name:  {closure}
number of ops:  10
compiled vars:  !0 = $x, !1 = $array2, !2 = $blank1
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
   39     3        INIT_FCALL                                               'array_merge'
          4        FETCH_DIM_R                                      ~3      !1, !0
          5        SEND_VAL                                                 ~3
          6        SEND_VAR                                                 !2
          7        DO_ICALL                                         $4      
          8      > RETURN                                                   $4
   40     9*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FlUAeN%3A37%243

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
202.57 ms | 1415 KiB | 34 Q