3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array1 = Array ( 0 => Array ( 'ID' => 101, 'Code' => 1075, 'Date' => '2012-03-03 17:13:12.433' ), 1 => Array ( 'ID' => 103, 'Code' => 175, 'Date' => '2012-09-05 20:30:02.217' ), 2 => Array ( 'ID' => 109, 'Code' => 178, 'Date' => '2012-07-05 20:30:02.217' ) ); $array2 = Array ( 0 => Array ( 'Amount' => 1234, 'ID' => 101 ), 1 => Array ( 'Amount' => 1342, 'ID' => 103 ), 2 => Array ( 'Amount' => 0, 'ID' => 0 ) ); $arr2 = array_column($array2, "ID"); $finalArray = array(); foreach($array1 as $arr){ $key = array_search($arr['ID'], $arr2); if($key ===false){ $key = array_search(0, $arr2); } unset($array2[$key]['ID']); $finalArray[] = array_merge($arr,$array2[$key]); } print_r($finalArray);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 33
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 33
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 23
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 23
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/1sDJs
function name:  (null)
number of ops:  38
compiled vars:  !0 = $array1, !1 = $array2, !2 = $arr2, !3 = $finalArray, !4 = $arr, !5 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   27     1        ASSIGN                                                   !1, <array>
   49     2        INIT_FCALL                                               'array_column'
          3        SEND_VAR                                                 !1
          4        SEND_VAL                                                 'ID'
          5        DO_ICALL                                         $8      
          6        ASSIGN                                                   !2, $8
   51     7        ASSIGN                                                   !3, <array>
   52     8      > FE_RESET_R                                       $11     !0, ->33
          9    > > FE_FETCH_R                                               $11, !4, ->33
   53    10    >   INIT_FCALL                                               'array_search'
         11        FETCH_DIM_R                                      ~12     !4, 'ID'
         12        SEND_VAL                                                 ~12
         13        SEND_VAR                                                 !2
         14        DO_ICALL                                         $13     
         15        ASSIGN                                                   !5, $13
   54    16        TYPE_CHECK                                    4          !5
         17      > JMPZ                                                     ~15, ->23
   55    18    >   INIT_FCALL                                               'array_search'
         19        SEND_VAL                                                 0
         20        SEND_VAR                                                 !2
         21        DO_ICALL                                         $16     
         22        ASSIGN                                                   !5, $16
   57    23    >   FETCH_DIM_UNSET                                  $18     !1, !5
         24        UNSET_DIM                                                $18, 'ID'
   58    25        INIT_FCALL                                               'array_merge'
         26        SEND_VAR                                                 !4
         27        FETCH_DIM_R                                      ~20     !1, !5
         28        SEND_VAL                                                 ~20
         29        DO_ICALL                                         $21     
         30        ASSIGN_DIM                                               !3
         31        OP_DATA                                                  $21
   52    32      > JMP                                                      ->9
         33    >   FE_FREE                                                  $11
   61    34        INIT_FCALL                                               'print_r'
         35        SEND_VAR                                                 !3
         36        DO_ICALL                                                 
         37      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.07 ms | 1009 KiB | 17 Q