3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ ["Reservation" => ["adult_price" => 200, "adult_count" => 2]], ["Reservation" => ["adult_price" => 200, "adult_count" => 1]], ["Reservation" => ["adult_price" => 300, "adult_count" => 1]], ["Reservation" => ["adult_price" => 200, "adult_count" => 1]], ]; $grouped = []; foreach ($array as $item) { $item = $item["Reservation"]; $currentValue = isset($grouped[$item["adult_price"]]) ? $grouped[$item["adult_price"]] : 0; $grouped[$item["adult_price"]] = $currentValue + $item["adult_count"]; } $buildArray = []; foreach ($grouped as $price => $count) { $buildArray[] = ["Reservation" => ["adult_price" => $price, "adult_count" => $count]]; } print_r($buildArray);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 21
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 21
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 13
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 21
2 jumps found. (Code = 77) Position 1 = 24, Position 2 = 32
Branch analysis from position: 24
2 jumps found. (Code = 78) Position 1 = 25, Position 2 = 32
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
Branch analysis from position: 21
filename:       /in/iZZ4m
function name:  (null)
number of ops:  37
compiled vars:  !0 = $array, !1 = $grouped, !2 = $item, !3 = $currentValue, !4 = $buildArray, !5 = $count, !6 = $price
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   10     1        ASSIGN                                                   !1, <array>
   12     2      > FE_RESET_R                                       $9      !0, ->21
          3    > > FE_FETCH_R                                               $9, !2, ->21
   13     4    >   FETCH_DIM_R                                      ~10     !2, 'Reservation'
          5        ASSIGN                                                   !2, ~10
   14     6        FETCH_DIM_R                                      ~12     !2, 'adult_price'
          7        ISSET_ISEMPTY_DIM_OBJ                         0          !1, ~12
          8      > JMPZ                                                     ~13, ->13
          9    >   FETCH_DIM_R                                      ~14     !2, 'adult_price'
         10        FETCH_DIM_R                                      ~15     !1, ~14
         11        QM_ASSIGN                                        ~16     ~15
         12      > JMP                                                      ->14
         13    >   QM_ASSIGN                                        ~16     0
         14    >   ASSIGN                                                   !3, ~16
   15    15        FETCH_DIM_R                                      ~18     !2, 'adult_price'
         16        FETCH_DIM_R                                      ~20     !2, 'adult_count'
         17        ADD                                              ~21     !3, ~20
         18        ASSIGN_DIM                                               !1, ~18
         19        OP_DATA                                                  ~21
   12    20      > JMP                                                      ->3
         21    >   FE_FREE                                                  $9
   18    22        ASSIGN                                                   !4, <array>
   20    23      > FE_RESET_R                                       $23     !1, ->32
         24    > > FE_FETCH_R                                       ~24     $23, !5, ->32
         25    >   ASSIGN                                                   !6, ~24
   21    26        INIT_ARRAY                                       ~27     !6, 'adult_price'
         27        ADD_ARRAY_ELEMENT                                ~27     !5, 'adult_count'
         28        INIT_ARRAY                                       ~28     ~27, 'Reservation'
         29        ASSIGN_DIM                                               !4
         30        OP_DATA                                                  ~28
   20    31      > JMP                                                      ->24
         32    >   FE_FREE                                                  $23
   24    33        INIT_FCALL                                               'print_r'
         34        SEND_VAR                                                 !4
         35        DO_ICALL                                                 
         36      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
127.36 ms | 1405 KiB | 15 Q