3v4l.org

run code in 300+ PHP versions simultaneously
<?php $newArr = array ( 100 => array ( 1 => array ( 'AVA_Date' => '2019-04-18', 'ROO_Id' => 100, 'RAT_Id' => 9 ), 2 => array ( 'AVA_Date' => '2019-04-20', 'ROO_Id' => 100, 'RAT_Id' => 10 ), 4 => array ( 'AVA_Date' => '2019-04-21', 'ROO_Id' => 100, 'RAT_Id' => 10 ), 7 => array ( 'AVA_Date' => '2019-04-22', 'ROO_Id' => 100, 'RAT_Id' => 9 ) ) ); foreach ($newArr as $key => $array) { $newArrOtherRooms[$key] = array_reduce($array, function($acc, $val) { $room = array_keys(array_column($acc, 'ROO_Id'), $val['ROO_Id']); $rate = array_keys(array_column($acc, 'RAT_Id'), $val['RAT_Id']); $common = array_intersect($room, $rate); if(!empty($common)) { array_push($acc[current($common)]['AVA_Date'], $val['AVA_Date']); } else { $new_arr = $val; $new_arr['AVA_Date'] = [$val['AVA_Date']]; array_push($acc, $new_arr); } return $acc; },[]); } print_r($newArrOtherRooms);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 13
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 13
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/IgG03
function name:  (null)
number of ops:  18
compiled vars:  !0 = $newArr, !1 = $array, !2 = $key, !3 = $newArrOtherRooms
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   32     1      > FE_RESET_R                                       $5      !0, ->13
          2    > > FE_FETCH_R                                       ~6      $5, !1, ->13
          3    >   ASSIGN                                                   !2, ~6
   33     4        INIT_FCALL                                               'array_reduce'
          5        SEND_VAR                                                 !1
          6        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FIgG03%3A33%240'
   46     7        SEND_VAL                                                 ~9
          8        SEND_VAL                                                 <array>
          9        DO_ICALL                                         $10     
   33    10        ASSIGN_DIM                                               !3, !2
   46    11        OP_DATA                                                  $10
   32    12      > JMP                                                      ->2
         13    >   FE_FREE                                                  $5
   48    14        INIT_FCALL                                               'print_r'
         15        SEND_VAR                                                 !3
         16        DO_ICALL                                                 
         17      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FIgG03%3A33%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 41
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IgG03
function name:  {closure}
number of ops:  52
compiled vars:  !0 = $acc, !1 = $val, !2 = $room, !3 = $rate, !4 = $common, !5 = $new_arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   34     2        INIT_FCALL                                               'array_keys'
          3        INIT_FCALL                                               'array_column'
          4        SEND_VAR                                                 !0
          5        SEND_VAL                                                 'ROO_Id'
          6        DO_ICALL                                         $6      
          7        SEND_VAR                                                 $6
          8        FETCH_DIM_R                                      ~7      !1, 'ROO_Id'
          9        SEND_VAL                                                 ~7
         10        DO_ICALL                                         $8      
         11        ASSIGN                                                   !2, $8
   35    12        INIT_FCALL                                               'array_keys'
         13        INIT_FCALL                                               'array_column'
         14        SEND_VAR                                                 !0
         15        SEND_VAL                                                 'RAT_Id'
         16        DO_ICALL                                         $10     
         17        SEND_VAR                                                 $10
         18        FETCH_DIM_R                                      ~11     !1, 'RAT_Id'
         19        SEND_VAL                                                 ~11
         20        DO_ICALL                                         $12     
         21        ASSIGN                                                   !3, $12
   36    22        INIT_FCALL                                               'array_intersect'
         23        SEND_VAR                                                 !2
         24        SEND_VAR                                                 !3
         25        DO_ICALL                                         $14     
         26        ASSIGN                                                   !4, $14
   37    27        ISSET_ISEMPTY_CV                                 ~16     !4
         28        BOOL_NOT                                         ~17     ~16
         29      > JMPZ                                                     ~17, ->41
   38    30    >   INIT_FCALL                                               'array_push'
         31        INIT_FCALL                                               'current'
         32        SEND_VAR                                                 !4
         33        DO_ICALL                                         $18     
         34        FETCH_DIM_W                                      $19     !0, $18
         35        FETCH_DIM_W                                      $20     $19, 'AVA_Date'
         36        SEND_REF                                                 $20
         37        FETCH_DIM_R                                      ~21     !1, 'AVA_Date'
         38        SEND_VAL                                                 ~21
         39        DO_ICALL                                                 
         40      > JMP                                                      ->50
   41    41    >   ASSIGN                                                   !5, !1
   42    42        FETCH_DIM_R                                      ~25     !1, 'AVA_Date'
         43        INIT_ARRAY                                       ~26     ~25
         44        ASSIGN_DIM                                               !5, 'AVA_Date'
         45        OP_DATA                                                  ~26
   43    46        INIT_FCALL                                               'array_push'
         47        SEND_REF                                                 !0
         48        SEND_VAR                                                 !5
         49        DO_ICALL                                                 
   45    50    > > RETURN                                                   !0
   46    51*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FIgG03%3A33%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.72 ms | 954 KiB | 28 Q