3v4l.org

run code in 500+ PHP versions simultaneously
<?php $array = [ 0 => [ "room_id" => "1", "date" => "01-07-2022", "available" => "A" ], 1 => [ "room_id" => "2", "date" => "01-07-2022", "available" => "A" ], 2 => [ "room_id" => "1", "date" => "02-07-2022", "available" => "A" ], 3 => [ "room_id" => "2", "date" => "02-07-2022", "available" => "U" ], 4 => [ "room_id" => "1", "date" => "03-07-2022", "available" => "U" ], 5 => [ "room_id" => "2", "date" => "03-07-2022", "available" => "U" ], 6 => [ "room_id" => "1", "date" => "04-07-2022", "available" => "U" ], ]; $hasVacancy = []; $result = []; foreach ($array as $row) { if ($row['available'] === 'A') { $hasVacancy[$row['date']] = $row; // store available as reference unset($result[$row['date']]); // remove potentially stored unavailable row for date } elseif (!isset($hasVacancy[$row['date']])) { $result[$row['date']] = $row; // is unavailable and no availables found } } var_export(array_values($result));
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 22
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 22
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 21
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 21
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/ucYP2
function name:  (null)
number of ops:  30
compiled vars:  !0 = $array, !1 = $hasVacancy, !2 = $result, !3 = $row
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   41     1        ASSIGN                                                       !1, <array>
   42     2        ASSIGN                                                       !2, <array>
   43     3      > FE_RESET_R                                           $7      !0, ->22
          4    > > FE_FETCH_R                                                   $7, !3, ->22
   44     5    >   FETCH_DIM_R                                          ~8      !3, 'available'
          6        IS_IDENTICAL                                                 ~8, 'A'
          7      > JMPZ                                                         ~9, ->14
   45     8    >   FETCH_DIM_R                                          ~10     !3, 'date'
          9        ASSIGN_DIM                                                   !1, ~10
         10        OP_DATA                                                      !3
   46    11        FETCH_DIM_R                                          ~12     !3, 'date'
         12        UNSET_DIM                                                    !2, ~12
   44    13      > JMP                                                          ->21
   47    14    >   FETCH_DIM_R                                          ~13     !3, 'date'
         15        ISSET_ISEMPTY_DIM_OBJ                             0  ~14     !1, ~13
         16        BOOL_NOT                                             ~15     ~14
         17      > JMPZ                                                         ~15, ->21
   48    18    >   FETCH_DIM_R                                          ~16     !3, 'date'
         19        ASSIGN_DIM                                                   !2, ~16
         20        OP_DATA                                                      !3
   43    21    > > JMP                                                          ->4
         22    >   FE_FREE                                                      $7
   51    23        INIT_FCALL                                                   'var_export'
         24        INIT_FCALL                                                   'array_values'
         25        SEND_VAR                                                     !2
         26        DO_ICALL                                             $18     
         27        SEND_VAR                                                     $18
         28        DO_ICALL                                                     
         29      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
143.23 ms | 1916 KiB | 15 Q