3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Set demo vars $year = '2012'; $months = array('10','11','12'); $days = array('01','02','03','04','06','07','08','09','11','12','13','14','16','17','18','19','21','22','23','24','26','27','28','30'); $dateWs = array(); foreach($months AS $month) foreach($days AS $day) $datesWS[] = new DateTime(implode('-',array(intval($year),intval($month),intval($day)))); // Push DateTime object to the WebService array var_dump(new DateTime('2012-12-30')); die(); // Shuffle shuffle($datesWS); // Sort dates usort($datesWS, function ($a, $b){ return ($a == $b) ? 0 : (($a > $b) ? 1 : -1); }); $dateIni = count($datesWS)>0 ? reset($datesWS) : 0; // Get first date $dateEnd = count($datesWS)>0 ? end($datesWS) : 0; // Get last date $interval = new DateInterval('P1D'); // Set date interval as 1 day // Generate dates range and Transform iterator to array $datesRange = iterator_to_array(new DatePeriod($dateIni, $interval, $dateEnd->modify( '+1 day' ))); var_dump(array_values(array_map(function($obj){ return $obj->format('d/m/Y'); },$datesWS))); die(); // This way seems to work foreach($datesRange AS $date) { if(!in_array($date->format('d/m/Y'),array_values(array_map(function($obj){ return $obj->format('d/m/Y'); },$datesWS)))) $excludeDates[] = $date->format('d/m/Y'); } var_dump($excludeDates); /* // This way should be more efficient, but I'm fed up with it! // Get excluded dates $excludeDates = array_udiff($datesRange, $datesWS, function ($a, $b) { return $a == $b ? 0 : 1; }); // Comment/Uncomment this in order to print this method or the other one // Print array(objects) as array(strings) var_dump(array_values(array_map(function($obj){ return $obj->format('d/m/Y'); },$datesWS))); var_dump(array_values(array_map(function($obj){ return $obj->format('d/m/Y'); },$datesRange))); var_dump(array_values(array_map(function($obj){ return $obj->format('d/m/Y'); },$excludeDates))); */ ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 26
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 26
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 24
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 24
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 24
Branch analysis from position: 26
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 26
filename:       /in/rARbB
function name:  (null)
number of ops:  120
compiled vars:  !0 = $year, !1 = $months, !2 = $days, !3 = $dateWs, !4 = $month, !5 = $day, !6 = $datesWS, !7 = $dateIni, !8 = $dateEnd, !9 = $interval, !10 = $datesRange, !11 = $date, !12 = $excludeDates
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, '2012'
    5     1        ASSIGN                                                   !1, <array>
    6     2        ASSIGN                                                   !2, <array>
    8     3        ASSIGN                                                   !3, <array>
    9     4      > FE_RESET_R                                       $17     !1, ->26
          5    > > FE_FETCH_R                                               $17, !4, ->26
   10     6    > > FE_RESET_R                                       $18     !2, ->24
          7    > > FE_FETCH_R                                               $18, !5, ->24
   11     8    >   NEW                                              $20     'DateTime'
          9        INIT_FCALL                                               'implode'
         10        SEND_VAL                                                 '-'
         11        CAST                                          4  ~21     !0
         12        INIT_ARRAY                                       ~22     ~21
         13        CAST                                          4  ~23     !4
         14        ADD_ARRAY_ELEMENT                                ~22     ~23
         15        CAST                                          4  ~24     !5
         16        ADD_ARRAY_ELEMENT                                ~22     ~24
         17        SEND_VAL                                                 ~22
         18        DO_ICALL                                         $25     
         19        SEND_VAR_NO_REF_EX                                       $25
         20        DO_FCALL                                      0          
         21        ASSIGN_DIM                                               !6
         22        OP_DATA                                                  $20
   10    23      > JMP                                                      ->7
         24    >   FE_FREE                                                  $18
    9    25      > JMP                                                      ->5
         26    >   FE_FREE                                                  $17
   13    27        INIT_FCALL                                               'var_dump'
         28        NEW                                              $27     'DateTime'
         29        SEND_VAL_EX                                              '2012-12-30'
         30        DO_FCALL                                      0          
         31        SEND_VAR                                                 $27
         32        DO_ICALL                                                 
   14    33      > EXIT                                                     
   17    34*       INIT_FCALL                                               'shuffle'
         35*       SEND_REF                                                 !6
         36*       DO_ICALL                                                 
   21    37*       INIT_FCALL                                               'usort'
         38*       SEND_REF                                                 !6
         39*       DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FrARbB%3A21%240'
   23    40*       SEND_VAL                                                 ~31
         41*       DO_ICALL                                                 
   25    42*       COUNT                                            ~33     !6
         43*       IS_SMALLER                                               0, ~33
         44*       JMPZ                                                     ~34, ->50
         45*       INIT_FCALL                                               'reset'
         46*       SEND_REF                                                 !6
         47*       DO_ICALL                                         $35     
         48*       QM_ASSIGN                                        ~36     $35
         49*       JMP                                                      ->51
         50*       QM_ASSIGN                                        ~36     0
         51*       ASSIGN                                                   !7, ~36
   26    52*       COUNT                                            ~38     !6
         53*       IS_SMALLER                                               0, ~38
         54*       JMPZ                                                     ~39, ->60
         55*       INIT_FCALL                                               'end'
         56*       SEND_REF                                                 !6
         57*       DO_ICALL                                         $40     
         58*       QM_ASSIGN                                        ~41     $40
         59*       JMP                                                      ->61
         60*       QM_ASSIGN                                        ~41     0
         61*       ASSIGN                                                   !8, ~41
   27    62*       NEW                                              $43     'DateInterval'
         63*       SEND_VAL_EX                                              'P1D'
         64*       DO_FCALL                                      0          
         65*       ASSIGN                                                   !9, $43
   30    66*       INIT_FCALL                                               'iterator_to_array'
         67*       NEW                                              $46     'DatePeriod'
         68*       SEND_VAR_EX                                              !7
         69*       SEND_VAR_EX                                              !9
         70*       INIT_METHOD_CALL                                         !8, 'modify'
         71*       SEND_VAL_EX                                              '%2B1+day'
         72*       DO_FCALL                                      0  $47     
         73*       SEND_VAR_NO_REF_EX                                       $47
         74*       DO_FCALL                                      0          
         75*       SEND_VAR                                                 $46
         76*       DO_ICALL                                         $49     
         77*       ASSIGN                                                   !10, $49
   32    78*       INIT_FCALL                                               'var_dump'
         79*       INIT_FCALL                                               'array_values'
         80*       INIT_FCALL                                               'array_map'
         81*       DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FrARbB%3A32%241'
   34    82*       SEND_VAL                                                 ~51
         83*       SEND_VAR                                                 !6
         84*       DO_ICALL                                         $52     
         85*       SEND_VAR                                                 $52
         86*       DO_ICALL                                         $53     
         87*       SEND_VAR                                                 $53
         88*       DO_ICALL                                                 
   35    89*       EXIT                                                     
   38    90*       FE_RESET_R                                       $55     !10, ->115
         91*       FE_FETCH_R                                               $55, !11, ->115
   40    92*       INIT_FCALL                                               'in_array'
         93*       INIT_METHOD_CALL                                         !11, 'format'
         94*       SEND_VAL_EX                                              'd%2Fm%2FY'
         95*       DO_FCALL                                      0  $56     
         96*       SEND_VAR                                                 $56
         97*       INIT_FCALL                                               'array_values'
         98*       INIT_FCALL                                               'array_map'
         99*       DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FrARbB%3A40%242'
   42   100*       SEND_VAL                                                 ~57
        101*       SEND_VAR                                                 !6
        102*       DO_ICALL                                         $58     
        103*       SEND_VAR                                                 $58
        104*       DO_ICALL                                         $59     
        105*       SEND_VAR                                                 $59
        106*       DO_ICALL                                         $60     
        107*       BOOL_NOT                                         ~61     $60
        108*       JMPZ                                                     ~61, ->114
   43   109*       INIT_METHOD_CALL                                         !11, 'format'
        110*       SEND_VAL_EX                                              'd%2Fm%2FY'
        111*       DO_FCALL                                      0  $63     
        112*       ASSIGN_DIM                                               !12
        113*       OP_DATA                                                  $63
   38   114*       JMP                                                      ->91
        115*       FE_FREE                                                  $55
   46   116*       INIT_FCALL                                               'var_dump'
        117*       SEND_VAR                                                 !12
        118*       DO_ICALL                                                 
   72   119*     > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FrARbB%3A21%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rARbB
function name:  {closure}
number of ops:  14
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   22     2        IS_EQUAL                                                 !0, !1
          3      > JMPZ                                                     ~2, ->6
          4    >   QM_ASSIGN                                        ~3      0
          5      > JMP                                                      ->12
          6    >   IS_SMALLER                                               !1, !0
          7      > JMPZ                                                     ~4, ->10
          8    >   QM_ASSIGN                                        ~5      1
          9      > JMP                                                      ->11
         10    >   QM_ASSIGN                                        ~5      -1
         11    >   QM_ASSIGN                                        ~3      ~5
         12    > > RETURN                                                   ~3
   23    13*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FrARbB%3A21%240

Function %00%7Bclosure%7D%2Fin%2FrARbB%3A32%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rARbB
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $obj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
   33     1        INIT_METHOD_CALL                                         !0, 'format'
          2        SEND_VAL_EX                                              'd%2Fm%2FY'
          3        DO_FCALL                                      0  $1      
          4      > RETURN                                                   $1
   34     5*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FrARbB%3A32%241

Function %00%7Bclosure%7D%2Fin%2FrARbB%3A40%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rARbB
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $obj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   RECV                                             !0      
   41     1        INIT_METHOD_CALL                                         !0, 'format'
          2        SEND_VAL_EX                                              'd%2Fm%2FY'
          3        DO_FCALL                                      0  $1      
          4      > RETURN                                                   $1
   42     5*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FrARbB%3A40%242

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.27 ms | 1408 KiB | 33 Q