3v4l.org

run code in 500+ PHP versions simultaneously
<?php $first = [ 3 => [0 => ['id' => 1, 'number' => 0, 'time' => 40,],], 4 => [0 => ['id' => 2, 'number' => 0, 'time' => 40,],], 5 => [0 => ['id' => 3, 'number' => 0, 'time' => 40,],], 6 => [0 => ['id' => 1, 'number' => 0, 'time' => 41,],], 7 => [0 => ['id' => 2, 'number' => 0, 'time' => 41,],], 8 => [0 => ['id' => 3, 'number' => 0, 'time' => 41,],], ]; $second = [3 => ['id' => '1', 'number' => '3785', 'time' => '40',], 4 => ['id' => '2', 'number' => '1574', 'time' => '40',], 5 => ['id' => '1', 'number' => '2954', 'time' => '41',], 6 => ['id' => '2', 'number' => '2463', 'time' => '41',], ]; $result = []; $secondMap = array_column($second, null, 'id'); foreach ($first as $key => $value) { foreach ($value as $item) { if (isset($secondMap[$item['id']])) { $result[$key] = $secondMap[$item['id']]; } else { $result[$key] = $value; } } } print_r($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 27
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 27
Branch analysis from position: 11
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 25
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 25
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 22
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 25
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
filename:       /in/7rfRe
function name:  (null)
number of ops:  32
compiled vars:  !0 = $first, !1 = $second, !2 = $result, !3 = $secondMap, !4 = $value, !5 = $key, !6 = $item
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   12     1        ASSIGN                                                       !1, <array>
   18     2        ASSIGN                                                       !2, <array>
   20     3        INIT_FCALL                                                   'array_column'
          4        SEND_VAR                                                     !1
          5        SEND_VAL                                                     null
          6        SEND_VAL                                                     'id'
          7        DO_ICALL                                             $10     
          8        ASSIGN                                                       !3, $10
   22     9      > FE_RESET_R                                           $12     !0, ->27
         10    > > FE_FETCH_R                                           ~13     $12, !4, ->27
         11    >   ASSIGN                                                       !5, ~13
   23    12      > FE_RESET_R                                           $15     !4, ->25
         13    > > FE_FETCH_R                                                   $15, !6, ->25
   24    14    >   FETCH_DIM_R                                          ~16     !6, 'id'
         15        ISSET_ISEMPTY_DIM_OBJ                             0          !3, ~16
         16      > JMPZ                                                         ~17, ->22
   25    17    >   FETCH_DIM_R                                          ~19     !6, 'id'
         18        FETCH_DIM_R                                          ~20     !3, ~19
         19        ASSIGN_DIM                                                   !2, !5
         20        OP_DATA                                                      ~20
   24    21      > JMP                                                          ->24
   27    22    >   ASSIGN_DIM                                                   !2, !5
         23        OP_DATA                                                      !4
   23    24    > > JMP                                                          ->13
         25    >   FE_FREE                                                      $15
   22    26      > JMP                                                          ->10
         27    >   FE_FREE                                                      $12
   31    28        INIT_FCALL                                                   'print_r'
         29        SEND_VAR                                                     !2
         30        DO_ICALL                                                     
         31      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
163.89 ms | 2037 KiB | 15 Q