3v4l.org

run code in 300+ PHP versions simultaneously
<?php $staff = array(1,2,3,4,5); $start = array("11:05", "11:00", "19:00", "13:00", "19:00"); $end = array("16:00", "17:00", "03:00", "16:00", "03:05"); // Add staff number to end of time ex 11:00 => 11:00#2 For($i=0; $i<count($start);$i++){ $start[$i] .= "#" . $staff[$i]; $end[$i] .= "#" . $staff[$i]; } $t = array_merge($start,$end); // create one long array with all in and out times sort($t); // Multisport is needed to get all arrays in time order as reference array_multisort($start, $end, $staff); // Find first start time (11:00) and slice array thwre, build string $test = implode(PHP_EOL,array_slice($t, array_search($start[0], $t))); // Find the times before first start (night end times) and add them last in string $test .= PHP_EOL . implode(PHP_EOL,array_slice($t, 0,array_search($start[0], $t))); $times = explode(PHP_EOL, $test); // explode to make it array again // Var_dump($times); $WhoIsInDaHouse = array("dummy"); // add a dummy variable since 0=false in later if $j=0; for($i=0; $i<count($times);$i++){ $TimePerson = explode("#", $times[$i]); $Time = $TimePerson[0]; $person = $TimePerson[1]; $inout = array_search($person, $WhoIsInDaHouse); //is person in house and about to leave? If($inout != false){ //if person enter work false, if true: key of person leaving in $WhoIsInDaHouse //Here $person is leaving work Unset($WhoIsInDaHouse[$inout]); If(count($WhoIsInDaHouse) == 2){ // someone will now be alone since we have a dummy $Alone[$j]["start"] = $Time; $Alone[$j]["who"] = array_slice($WhoIsInDaHouse, -1)[0]; }elseif(count($WhoIsInDaHouse) == 1 && $prevcount == 2){ // Only dummy left $Alone[$j]["end"] = $Time; $Alone[$j]["duration"] = strtotime($Alone[$j]["end"])-strtotime($Alone[$j]["start"]); $j++; } }Else{ // Here person enters work $WhoIsInDaHouse[] = $person; If(count($WhoIsInDaHouse) == 2){ // someone is entering alone $Alone[$j]["start"] = $Time; $Alone[$j]["who"] = $person; }elseif(count($WhoIsInDaHouse)>2 && $prevcount == 2){ // not alone anymore $Alone[$j]["end"] = $Time; $Alone[$j]["duration"] = strtotime($Alone[$j]["end"])-strtotime($Alone[$j]["start"]); $j++; } } $prevcount = count($WhoIsInDaHouse); } Var_dump($Alone);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 5
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 166
Branch analysis from position: 166
2 jumps found. (Code = 44) Position 1 = 169, Position 2 = 69
Branch analysis from position: 169
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 69
2 jumps found. (Code = 43) Position 1 = 86, Position 2 = 127
Branch analysis from position: 86
2 jumps found. (Code = 43) Position 1 = 90, Position 2 = 102
Branch analysis from position: 90
1 jumps found. (Code = 42) Position 1 = 126
Branch analysis from position: 126
1 jumps found. (Code = 42) Position 1 = 163
Branch analysis from position: 163
2 jumps found. (Code = 44) Position 1 = 169, Position 2 = 69
Branch analysis from position: 169
Branch analysis from position: 69
Branch analysis from position: 102
2 jumps found. (Code = 46) Position 1 = 105, Position 2 = 107
Branch analysis from position: 105
2 jumps found. (Code = 43) Position 1 = 108, Position 2 = 126
Branch analysis from position: 108
1 jumps found. (Code = 42) Position 1 = 163
Branch analysis from position: 163
Branch analysis from position: 126
Branch analysis from position: 107
Branch analysis from position: 127
2 jumps found. (Code = 43) Position 1 = 132, Position 2 = 139
Branch analysis from position: 132
1 jumps found. (Code = 42) Position 1 = 163
Branch analysis from position: 163
Branch analysis from position: 139
2 jumps found. (Code = 46) Position 1 = 142, Position 2 = 144
Branch analysis from position: 142
2 jumps found. (Code = 43) Position 1 = 145, Position 2 = 163
Branch analysis from position: 145
2 jumps found. (Code = 44) Position 1 = 169, Position 2 = 69
Branch analysis from position: 169
Branch analysis from position: 69
Branch analysis from position: 163
Branch analysis from position: 144
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 17, Position 2 = 5
Branch analysis from position: 17
Branch analysis from position: 5
filename:       /in/dCL2H
function name:  (null)
number of ops:  173
compiled vars:  !0 = $staff, !1 = $start, !2 = $end, !3 = $i, !4 = $t, !5 = $test, !6 = $times, !7 = $WhoIsInDaHouse, !8 = $j, !9 = $TimePerson, !10 = $Time, !11 = $person, !12 = $inout, !13 = $Alone, !14 = $prevcount
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, <array>
    5     2        ASSIGN                                                   !2, <array>
    8     3        ASSIGN                                                   !3, 0
          4      > JMP                                                      ->14
    9     5    >   FETCH_DIM_R                                      ~20     !0, !3
          6        CONCAT                                           ~21     '%23', ~20
          7        ASSIGN_DIM_OP                .=               8          !1, !3
          8        OP_DATA                                                  ~21
   10     9        FETCH_DIM_R                                      ~23     !0, !3
         10        CONCAT                                           ~24     '%23', ~23
         11        ASSIGN_DIM_OP                .=               8          !2, !3
         12        OP_DATA                                                  ~24
    8    13        PRE_INC                                                  !3
         14    >   COUNT                                            ~26     !1
         15        IS_SMALLER                                               !3, ~26
         16      > JMPNZ                                                    ~27, ->5
   13    17    >   INIT_FCALL                                               'array_merge'
         18        SEND_VAR                                                 !1
         19        SEND_VAR                                                 !2
         20        DO_ICALL                                         $28     
         21        ASSIGN                                                   !4, $28
   14    22        INIT_FCALL                                               'sort'
         23        SEND_REF                                                 !4
         24        DO_ICALL                                                 
   17    25        INIT_FCALL                                               'array_multisort'
         26        SEND_REF                                                 !1
         27        SEND_REF                                                 !2
         28        SEND_REF                                                 !0
         29        DO_ICALL                                                 
   20    30        INIT_FCALL                                               'implode'
         31        SEND_VAL                                                 '%0A'
         32        INIT_FCALL                                               'array_slice'
         33        SEND_VAR                                                 !4
         34        INIT_FCALL                                               'array_search'
         35        FETCH_DIM_R                                      ~32     !1, 0
         36        SEND_VAL                                                 ~32
         37        SEND_VAR                                                 !4
         38        DO_ICALL                                         $33     
         39        SEND_VAR                                                 $33
         40        DO_ICALL                                         $34     
         41        SEND_VAR                                                 $34
         42        DO_ICALL                                         $35     
         43        ASSIGN                                                   !5, $35
   23    44        INIT_FCALL                                               'implode'
         45        SEND_VAL                                                 '%0A'
         46        INIT_FCALL                                               'array_slice'
         47        SEND_VAR                                                 !4
         48        SEND_VAL                                                 0
         49        INIT_FCALL                                               'array_search'
         50        FETCH_DIM_R                                      ~37     !1, 0
         51        SEND_VAL                                                 ~37
         52        SEND_VAR                                                 !4
         53        DO_ICALL                                         $38     
         54        SEND_VAR                                                 $38
         55        DO_ICALL                                         $39     
         56        SEND_VAR                                                 $39
         57        DO_ICALL                                         $40     
         58        CONCAT                                           ~41     '%0A', $40
         59        ASSIGN_OP                                     8          !5, ~41
   24    60        INIT_FCALL                                               'explode'
         61        SEND_VAL                                                 '%0A'
         62        SEND_VAR                                                 !5
         63        DO_ICALL                                         $43     
         64        ASSIGN                                                   !6, $43
   27    65        ASSIGN                                                   !7, <array>
   28    66        ASSIGN                                                   !8, 0
   29    67        ASSIGN                                                   !3, 0
         68      > JMP                                                      ->166
   30    69    >   INIT_FCALL                                               'explode'
         70        SEND_VAL                                                 '%23'
         71        FETCH_DIM_R                                      ~48     !6, !3
         72        SEND_VAL                                                 ~48
         73        DO_ICALL                                         $49     
         74        ASSIGN                                                   !9, $49
   31    75        FETCH_DIM_R                                      ~51     !9, 0
         76        ASSIGN                                                   !10, ~51
   32    77        FETCH_DIM_R                                      ~53     !9, 1
         78        ASSIGN                                                   !11, ~53
   35    79        INIT_FCALL                                               'array_search'
         80        SEND_VAR                                                 !11
         81        SEND_VAR                                                 !7
         82        DO_ICALL                                         $55     
         83        ASSIGN                                                   !12, $55
   36    84        BOOL                                             ~57     !12
         85      > JMPZ                                                     ~57, ->127
   38    86    >   UNSET_DIM                                                !7, !12
   40    87        COUNT                                            ~58     !7
         88        IS_EQUAL                                                 ~58, 2
         89      > JMPZ                                                     ~59, ->102
   41    90    >   FETCH_DIM_W                                      $60     !13, !8
         91        ASSIGN_DIM                                               $60, 'start'
         92        OP_DATA                                                  !10
   42    93        INIT_FCALL                                               'array_slice'
         94        SEND_VAR                                                 !7
         95        SEND_VAL                                                 -1
         96        DO_ICALL                                         $64     
         97        FETCH_DIM_R                                      ~65     $64, 0
         98        FETCH_DIM_W                                      $62     !13, !8
         99        ASSIGN_DIM                                               $62, 'who'
        100        OP_DATA                                                  ~65
   40   101      > JMP                                                      ->126
   43   102    >   COUNT                                            ~66     !7
        103        IS_EQUAL                                         ~67     ~66, 1
        104      > JMPZ_EX                                          ~67     ~67, ->107
        105    >   IS_EQUAL                                         ~68     !14, 2
        106        BOOL                                             ~67     ~68
        107    > > JMPZ                                                     ~67, ->126
   45   108    >   FETCH_DIM_W                                      $69     !13, !8
        109        ASSIGN_DIM                                               $69, 'end'
        110        OP_DATA                                                  !10
   46   111        INIT_FCALL                                               'strtotime'
        112        FETCH_DIM_R                                      ~73     !13, !8
        113        FETCH_DIM_R                                      ~74     ~73, 'end'
        114        SEND_VAL                                                 ~74
        115        DO_ICALL                                         $75     
        116        INIT_FCALL                                               'strtotime'
        117        FETCH_DIM_R                                      ~76     !13, !8
        118        FETCH_DIM_R                                      ~77     ~76, 'start'
        119        SEND_VAL                                                 ~77
        120        DO_ICALL                                         $78     
        121        SUB                                              ~79     $75, $78
        122        FETCH_DIM_W                                      $71     !13, !8
        123        ASSIGN_DIM                                               $71, 'duration'
        124        OP_DATA                                                  ~79
   47   125        PRE_INC                                                  !8
   36   126    > > JMP                                                      ->163
   51   127    >   ASSIGN_DIM                                               !7
        128        OP_DATA                                                  !11
   53   129        COUNT                                            ~82     !7
        130        IS_EQUAL                                                 ~82, 2
        131      > JMPZ                                                     ~83, ->139
   54   132    >   FETCH_DIM_W                                      $84     !13, !8
        133        ASSIGN_DIM                                               $84, 'start'
        134        OP_DATA                                                  !10
   55   135        FETCH_DIM_W                                      $86     !13, !8
        136        ASSIGN_DIM                                               $86, 'who'
        137        OP_DATA                                                  !11
   53   138      > JMP                                                      ->163
   56   139    >   COUNT                                            ~88     !7
        140        IS_SMALLER                                       ~89     2, ~88
        141      > JMPZ_EX                                          ~89     ~89, ->144
        142    >   IS_EQUAL                                         ~90     !14, 2
        143        BOOL                                             ~89     ~90
        144    > > JMPZ                                                     ~89, ->163
   57   145    >   FETCH_DIM_W                                      $91     !13, !8
        146        ASSIGN_DIM                                               $91, 'end'
        147        OP_DATA                                                  !10
   58   148        INIT_FCALL                                               'strtotime'
        149        FETCH_DIM_R                                      ~95     !13, !8
        150        FETCH_DIM_R                                      ~96     ~95, 'end'
        151        SEND_VAL                                                 ~96
        152        DO_ICALL                                         $97     
        153        INIT_FCALL                                               'strtotime'
        154        FETCH_DIM_R                                      ~98     !13, !8
        155        FETCH_DIM_R                                      ~99     ~98, 'start'
        156        SEND_VAL                                                 ~99
        157        DO_ICALL                                         $100    
        158        SUB                                              ~101    $97, $100
        159        FETCH_DIM_W                                      $93     !13, !8
        160        ASSIGN_DIM                                               $93, 'duration'
        161        OP_DATA                                                  ~101
   59   162        PRE_INC                                                  !8
   62   163    >   COUNT                                            ~103    !7
        164        ASSIGN                                                   !14, ~103
   29   165        PRE_INC                                                  !3
        166    >   COUNT                                            ~106    !6
        167        IS_SMALLER                                               !3, ~106
        168      > JMPNZ                                                    ~107, ->69
   64   169    >   INIT_FCALL                                               'var_dump'
        170        SEND_VAR                                                 !13
        171        DO_ICALL                                                 
        172      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.21 ms | 1024 KiB | 22 Q