3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr1 = [ ['customer_id' => 1, 'Expire' => '2019-05-14', 'paid' => 1], ['customer_id' => 2, 'Expire' => '2019-06-20', 'paid' => 0], ['customer_id' => 2, 'Expire' => '2019-06-21', 'paid' => 1], ]; $arr2 = [ ['id' => 3943, 'customer_id' => 1, 'Expire' => '2019-05-14'], ['id' => 3944, 'customer_id' => 1, 'Expire' => '2019-05-14'], ['id' => 4713, 'customer_id' => 2, 'Expire' => '2019-06-20'], ['id' => 4714, 'customer_id' => 2, 'Expire' => '2019-06-21'] ]; foreach ($arr2 as &$a) { // Find the sub-array of $arr1 that matches this array's date and ID $arr1_match = array_filter($arr1, function($v) use ($a) { return $v['customer_id'] == $a['customer_id'] && $v['Expire'] == $a['Expire']; }); // Get the first element from the result $paid = reset($arr1_match)['paid']; // Append the paid-value to this array (done by reference) $a['paid'] = $paid; } print_r($arr2);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 3, Position 2 = 19
Branch analysis from position: 3
2 jumps found. (Code = 126) Position 1 = 4, Position 2 = 19
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/mov6d
function name:  (null)
number of ops:  24
compiled vars:  !0 = $arr1, !1 = $arr2, !2 = $a, !3 = $arr1_match, !4 = $paid
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    9     1        ASSIGN                                                   !1, <array>
   16     2      > FE_RESET_RW                                      $7      !1, ->19
          3    > > FE_FETCH_RW                                              $7, !2, ->19
   18     4    >   INIT_FCALL                                               'array_filter'
          5        SEND_VAR                                                 !0
          6        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fmov6d%3A18%240'
          7        BIND_LEXICAL                                             ~8, !2
   20     8        SEND_VAL                                                 ~8
          9        DO_ICALL                                         $9      
   18    10        ASSIGN                                                   !3, $9
   22    11        INIT_FCALL                                               'reset'
         12        SEND_REF                                                 !3
         13        DO_ICALL                                         $11     
         14        FETCH_DIM_R                                      ~12     $11, 'paid'
         15        ASSIGN                                                   !4, ~12
   24    16        ASSIGN_DIM                                               !2, 'paid'
         17        OP_DATA                                                  !4
   16    18      > JMP                                                      ->3
         19    >   FE_FREE                                                  $7
   27    20        INIT_FCALL                                               'print_r'
         21        SEND_VAR                                                 !1
         22        DO_ICALL                                                 
         23      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2Fmov6d%3A18%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/mov6d
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $v, !1 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   19     2        FETCH_DIM_R                                      ~2      !0, 'customer_id'
          3        FETCH_DIM_R                                      ~3      !1, 'customer_id'
          4        IS_EQUAL                                         ~4      ~2, ~3
          5      > JMPZ_EX                                          ~4      ~4, ->10
          6    >   FETCH_DIM_R                                      ~5      !0, 'Expire'
          7        FETCH_DIM_R                                      ~6      !1, 'Expire'
          8        IS_EQUAL                                         ~7      ~5, ~6
          9        BOOL                                             ~4      ~7
         10    > > RETURN                                                   ~4
   20    11*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Fmov6d%3A18%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.01 ms | 1405 KiB | 19 Q