3v4l.org

run code in 500+ PHP versions simultaneously
<?php function weekCounter($startDate,$endDate=null){ //use today as endDate if no date was supplied $endDate = $endDate? : date('Y-m-d'); //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 //increment from 0-base to 1-base, so first week is Week 1. Same with months $fullMonths++; $weeksRemainder++; return [$fullMonths,$weeksRemainder]; } $startDate = '2016-06-27'; //put function results in $months and $weeks variables list($months,$weeks) = weekCounter($startDate); //you can use the variables however you want echo "Month: $months, Week: $weeks";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qY2OX
function name:  (null)
number of ops:  15
compiled vars:  !0 = $startDate, !1 = $months, !2 = $weeks
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   20     0  E >   ASSIGN                                                       !0, '2016-06-27'
   23     1        INIT_FCALL                                                   'weekcounter'
          2        SEND_VAR                                                     !0
          3        DO_FCALL                                          0  $4      
          4        FETCH_LIST_R                                         $5      $4, 0
          5        ASSIGN                                                       !1, $5
          6        FETCH_LIST_R                                         $7      $4, 1
          7        ASSIGN                                                       !2, $7
          8        FREE                                                         $4
   26     9        ROPE_INIT                                         4  ~10     'Month%3A+'
         10        ROPE_ADD                                          1  ~10     ~10, !1
         11        ROPE_ADD                                          2  ~10     ~10, '%2C+Week%3A+'
         12        ROPE_END                                          3  ~9      ~10, !2
         13        ECHO                                                         ~9
         14      > RETURN                                                       1

Function weekcounter:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qY2OX
function name:  weekCounter
number of ops:  34
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_INIT                                            !1      null
    5     2        JMP_SET                                              ~6      !1, ->7
          3        INIT_FCALL                                                   'date'
          4        SEND_VAL                                                     'Y-m-d'
          5        DO_ICALL                                             $7      
          6        QM_ASSIGN                                            ~6      $7
          7        ASSIGN                                                       !1, ~6
    8     8        ASSIGN                                                       !2, 604800
   10     9        INIT_FCALL                                                   'floor'
         10        INIT_FCALL                                                   'strtotime'
         11        SEND_VAR                                                     !1
         12        DO_ICALL                                             $10     
         13        INIT_FCALL                                                   'strtotime'
         14        SEND_VAR                                                     !0
         15        DO_ICALL                                             $11     
         16        SUB                                                  ~12     $10, $11
         17        DIV                                                  ~13     ~12, !2
         18        SEND_VAL                                                     ~13
         19        DO_ICALL                                             $14     
    9    20        ASSIGN                                                       !3, $14
   12    21        INIT_FCALL                                                   'floor'
         22        DIV                                                  ~16     !3, 4
         23        SEND_VAL                                                     ~16
         24        DO_ICALL                                             $17     
         25        ASSIGN                                                       !4, $17
   13    26        MOD                                                  ~19     !3, 4
         27        ASSIGN                                                       !5, ~19
   16    28        PRE_INC                                                      !4
         29        PRE_INC                                                      !5
   18    30        INIT_ARRAY                                           ~23     !4
         31        ADD_ARRAY_ELEMENT                                    ~23     !5
         32      > RETURN                                                       ~23
   19    33*     > RETURN                                                       null

End of function weekcounter

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
159.02 ms | 3314 KiB | 17 Q