3v4l.org

run code in 300+ PHP versions simultaneously
<?php function weekCounter($startDate,$endDate){ //calculate # of full weeks between dates $secsPerWeek = 60 * 60 * 24 * 7; $fullWeeks = floor((strtotime($endDate) - strtotime($startDate))/$secsPerWeek); $fullMonths = floor($fullWeeks/4); $weeksRemainder = $fullWeeks % 4; // weeks that don't fit in a month return "Months: $fullMonths, Weeks: $weeksRemainder"; } $startDate = '2016-06-13'; $endDates = ['2016-06-20','2016-06-27','2016-07-04']; foreach($endDates as $endDate) echo weekCounter($startDate,$endDate)."\n";
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 11
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/g59eE
function name:  (null)
number of ops:  13
compiled vars:  !0 = $startDate, !1 = $endDates, !2 = $endDate
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   ASSIGN                                                   !0, '2016-06-13'
   13     1        ASSIGN                                                   !1, <array>
   14     2      > FE_RESET_R                                       $5      !1, ->11
          3    > > FE_FETCH_R                                               $5, !2, ->11
          4    >   INIT_FCALL                                               'weekcounter'
          5        SEND_VAR                                                 !0
          6        SEND_VAR                                                 !2
          7        DO_FCALL                                      0  $6      
          8        CONCAT                                           ~7      $6, '%0A'
          9        ECHO                                                     ~7
         10      > JMP                                                      ->3
         11    >   FE_FREE                                                  $5
         12      > RETURN                                                   1

Function weekcounter:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/g59eE
function name:  weekCounter
number of ops:  28
compiled vars:  !0 = $startDate, !1 = $endDate, !2 = $secsPerWeek, !3 = $fullWeeks, !4 = $fullMonths, !5 = $weeksRemainder
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        ASSIGN                                                   !2, 604800
    5     3        INIT_FCALL                                               'floor'
          4        INIT_FCALL                                               'strtotime'
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $7      
          7        INIT_FCALL                                               'strtotime'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $8      
         10        SUB                                              ~9      $7, $8
         11        DIV                                              ~10     ~9, !2
         12        SEND_VAL                                                 ~10
         13        DO_ICALL                                         $11     
         14        ASSIGN                                                   !3, $11
    7    15        INIT_FCALL                                               'floor'
         16        DIV                                              ~13     !3, 4
         17        SEND_VAL                                                 ~13
         18        DO_ICALL                                         $14     
         19        ASSIGN                                                   !4, $14
    8    20        MOD                                              ~16     !3, 4
         21        ASSIGN                                                   !5, ~16
   10    22        ROPE_INIT                                     4  ~19     'Months%3A+'
         23        ROPE_ADD                                      1  ~19     ~19, !4
         24        ROPE_ADD                                      2  ~19     ~19, '%2C+Weeks%3A+'
         25        ROPE_END                                      3  ~18     ~19, !5
         26      > RETURN                                                   ~18
   11    27*     > RETURN                                                   null

End of function weekcounter

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.94 ms | 1403 KiB | 18 Q