3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Apm { public $duration; function __construct($duration) { $this->duration = $duration; } } $apps = [ "09:00" => new Apm(45), "09:15" => "", // I want to delete this row -> 15 minutes "09:30" => "", // I want to delete this row -> 30 minutes end of the appointment "09:45" => "", "10:00" => new Apm(60), "10:15" => "", // I want to delete this row -> 15 minutes "10:30" => "", // I want to delete this row -> 30 minutes "10:45" => "", // I want to delete this row -> 45 minutes "11:00" => "", // I want to delete this row -> 60 minutes end of the appointment "11:15" => "", "11:30" => "", "11:45" => new Apm(90), ]; $duration = 0; $filtered = array_filter( $apps, function ($apm) use (&$duration) { if ($duration === 0) { if (!empty($apm->duration)) { $duration = $apm->duration - 15; return true; } else { return true; } } else { $duration -= 15; return false; } } ); print_r($filtered);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BY9u7
function name:  (null)
number of ops:  34
compiled vars:  !0 = $apps, !1 = $duration, !2 = $filtered
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   NEW                                              $3      'Apm'
          1        SEND_VAL_EX                                              45
          2        DO_FCALL                                      0          
          3        INIT_ARRAY                                       ~5      $3, '09%3A00'
   12     4        ADD_ARRAY_ELEMENT                                ~5      '', '09%3A15'
   13     5        ADD_ARRAY_ELEMENT                                ~5      '', '09%3A30'
   14     6        ADD_ARRAY_ELEMENT                                ~5      '', '09%3A45'
   15     7        NEW                                              $6      'Apm'
          8        SEND_VAL_EX                                              60
          9        DO_FCALL                                      0          
         10        ADD_ARRAY_ELEMENT                                ~5      $6, '10%3A00'
   16    11        ADD_ARRAY_ELEMENT                                ~5      '', '10%3A15'
   17    12        ADD_ARRAY_ELEMENT                                ~5      '', '10%3A30'
   18    13        ADD_ARRAY_ELEMENT                                ~5      '', '10%3A45'
   19    14        ADD_ARRAY_ELEMENT                                ~5      '', '11%3A00'
   20    15        ADD_ARRAY_ELEMENT                                ~5      '', '11%3A15'
   21    16        ADD_ARRAY_ELEMENT                                ~5      '', '11%3A30'
   22    17        NEW                                              $8      'Apm'
         18        SEND_VAL_EX                                              90
         19        DO_FCALL                                      0          
         20        ADD_ARRAY_ELEMENT                                ~5      $8, '11%3A45'
   10    21        ASSIGN                                                   !0, ~5
   24    22        ASSIGN                                                   !1, 0
   25    23        INIT_FCALL                                               'array_filter'
   26    24        SEND_VAR                                                 !0
   27    25        DECLARE_LAMBDA_FUNCTION                          ~12     [0]
         26        BIND_LEXICAL                                             ~12, !1
   39    27        SEND_VAL                                                 ~12
   25    28        DO_ICALL                                         $13     
         29        ASSIGN                                                   !2, $13
   42    30        INIT_FCALL                                               'print_r'
         31        SEND_VAR                                                 !2
         32        DO_ICALL                                                 
         33      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 14
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 12
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BY9u7
function name:  {closure}
number of ops:  17
compiled vars:  !0 = $apm, !1 = $duration
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   28     2        IS_IDENTICAL                                             !1, 0
          3      > JMPZ                                                     ~2, ->14
   29     4    >   ISSET_ISEMPTY_PROP_OBJ                           ~3      !0, 'duration'
          5        BOOL_NOT                                         ~4      ~3
          6      > JMPZ                                                     ~4, ->12
   30     7    >   FETCH_OBJ_R                                      ~5      !0, 'duration'
          8        SUB                                              ~6      ~5, 15
          9        ASSIGN                                                   !1, ~6
   31    10      > RETURN                                                   <true>
   29    11*       JMP                                                      ->13
   33    12    > > RETURN                                                   <true>
   28    13*       JMP                                                      ->16
   36    14    >   ASSIGN_OP                                     2          !1, 15
   37    15      > RETURN                                                   <false>
   39    16*     > RETURN                                                   null

End of Dynamic Function 0

Class Apm:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BY9u7
function name:  __construct
number of ops:  4
compiled vars:  !0 = $duration
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    6     1        ASSIGN_OBJ                                               'duration'
          2        OP_DATA                                                  !0
    7     3      > RETURN                                                   null

End of function __construct

End of class Apm.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
135.45 ms | 1016 KiB | 15 Q