3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a[] = ["ID" => 101, "CODE" => 1]; $a[] = ["ID" => 105, "CODE" => 2]; $a[] = ["ID" => 109, "CODE" => 2]; $b[] = ["ID" => 105, "Amount" => 200]; $b[] = ["ID" => 101, "Amount" => 100]; $keys = array_merge(array_keys($a[0]), array_keys($b[0])); $template = array_combine($keys, array_fill(0, count($keys), null)); $a = array_column($a, null, "ID"); $b = array_column($b, null, "ID"); ksort($a); ksort($b); $res = array_map(function ($e1, $e2) use ($template){ if ($e1 && $e2) return array_merge($e1, $e2); $e = $e1 ? $e1 : $e2; return array_replace ($template, $e); }, $a, $b); print_r($res);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hnC20
function name:  (null)
number of ops:  64
compiled vars:  !0 = $a, !1 = $b, !2 = $keys, !3 = $template, !4 = $res
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN_DIM                                               !0
          1        OP_DATA                                                  <array>
    4     2        ASSIGN_DIM                                               !0
          3        OP_DATA                                                  <array>
    5     4        ASSIGN_DIM                                               !0
          5        OP_DATA                                                  <array>
    7     6        ASSIGN_DIM                                               !1
          7        OP_DATA                                                  <array>
    8     8        ASSIGN_DIM                                               !1
          9        OP_DATA                                                  <array>
   11    10        INIT_FCALL                                               'array_merge'
         11        INIT_FCALL                                               'array_keys'
         12        FETCH_DIM_R                                      ~10     !0, 0
         13        SEND_VAL                                                 ~10
         14        DO_ICALL                                         $11     
         15        SEND_VAR                                                 $11
         16        INIT_FCALL                                               'array_keys'
         17        FETCH_DIM_R                                      ~12     !1, 0
         18        SEND_VAL                                                 ~12
         19        DO_ICALL                                         $13     
         20        SEND_VAR                                                 $13
         21        DO_ICALL                                         $14     
         22        ASSIGN                                                   !2, $14
   12    23        INIT_FCALL                                               'array_combine'
         24        SEND_VAR                                                 !2
         25        INIT_FCALL                                               'array_fill'
         26        SEND_VAL                                                 0
         27        COUNT                                            ~16     !2
         28        SEND_VAL                                                 ~16
         29        SEND_VAL                                                 null
         30        DO_ICALL                                         $17     
         31        SEND_VAR                                                 $17
         32        DO_ICALL                                         $18     
         33        ASSIGN                                                   !3, $18
   14    34        INIT_FCALL                                               'array_column'
         35        SEND_VAR                                                 !0
         36        SEND_VAL                                                 null
         37        SEND_VAL                                                 'ID'
         38        DO_ICALL                                         $20     
         39        ASSIGN                                                   !0, $20
   15    40        INIT_FCALL                                               'array_column'
         41        SEND_VAR                                                 !1
         42        SEND_VAL                                                 null
         43        SEND_VAL                                                 'ID'
         44        DO_ICALL                                         $22     
         45        ASSIGN                                                   !1, $22
   17    46        INIT_FCALL                                               'ksort'
         47        SEND_REF                                                 !0
         48        DO_ICALL                                                 
   18    49        INIT_FCALL                                               'ksort'
         50        SEND_REF                                                 !1
         51        DO_ICALL                                                 
   21    52        INIT_FCALL                                               'array_map'
         53        DECLARE_LAMBDA_FUNCTION                          ~26     [0]
         54        BIND_LEXICAL                                             ~26, !3
   25    55        SEND_VAL                                                 ~26
         56        SEND_VAR                                                 !0
         57        SEND_VAR                                                 !1
   21    58        DO_ICALL                                         $27     
         59        ASSIGN                                                   !4, $27
   27    60        INIT_FCALL                                               'print_r'
         61        SEND_VAR                                                 !4
         62        DO_ICALL                                                 
         63      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 11
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
filename:       /in/hnC20
function name:  {closure}
number of ops:  22
compiled vars:  !0 = $e1, !1 = $e2, !2 = $template, !3 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   22     3      > JMPZ_EX                                          ~4      !0, ->5
          4    >   BOOL                                             ~4      !1
          5    > > JMPZ                                                     ~4, ->11
          6    >   INIT_FCALL                                               'array_merge'
          7        SEND_VAR                                                 !0
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $5      
         10      > RETURN                                                   $5
   23    11    > > JMPZ                                                     !0, ->14
         12    >   QM_ASSIGN                                        ~6      !0
         13      > JMP                                                      ->15
         14    >   QM_ASSIGN                                        ~6      !1
         15    >   ASSIGN                                                   !3, ~6
   24    16        INIT_FCALL                                               'array_replace'
         17        SEND_VAR                                                 !2
         18        SEND_VAR                                                 !3
         19        DO_ICALL                                         $8      
         20      > RETURN                                                   $8
   25    21*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.14 ms | 1034 KiB | 22 Q