3v4l.org

run code in 300+ PHP versions simultaneously
<?php //echo date('r', strtotime('last sunday', strtotime('6 April 1991'))); function align_timestamp_to($stamp, $unit, $past){ // timestamp, unit string, start/end static $modes = array( 'week' => 'last monday', 'month' => 'first day of month', ); // TODO error out if unknown $unit $offset = $modes[$unit]; if($past == 'end')$offset = '+1 '.$unit.' '.$offset; $new = strtotime($offset, $stamp); } foreach(array( array(strtotime('4 Apr 2012'), 'week', 'start'), array(strtotime('4 Apr 2012'), 'week', 'end'), ) as $test)echo date('r', $test[0]).' aligned '.$test[2].' of '.$test[1].' yields '.date('r', align_timestamp_to($test[0], $test[1], $test[2])).'<br/>';
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 44
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 44
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
filename:       /in/WKOP1
function name:  (null)
number of ops:  46
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   INIT_FCALL                                               'strtotime'
          1        SEND_VAL                                                 '4+Apr+2012'
          2        DO_ICALL                                         $1      
          3        INIT_ARRAY                                       ~2      $1
          4        ADD_ARRAY_ELEMENT                                ~2      'week'
          5        ADD_ARRAY_ELEMENT                                ~2      'start'
          6        INIT_ARRAY                                       ~3      ~2
   18     7        INIT_FCALL                                               'strtotime'
          8        SEND_VAL                                                 '4+Apr+2012'
          9        DO_ICALL                                         $4      
         10        INIT_ARRAY                                       ~5      $4
         11        ADD_ARRAY_ELEMENT                                ~5      'week'
         12        ADD_ARRAY_ELEMENT                                ~5      'end'
         13        ADD_ARRAY_ELEMENT                                ~3      ~5
         14      > FE_RESET_R                                       $6      ~3, ->44
         15    > > FE_FETCH_R                                               $6, !0, ->44
   19    16    >   INIT_FCALL                                               'date'
         17        SEND_VAL                                                 'r'
         18        FETCH_DIM_R                                      ~7      !0, 0
         19        SEND_VAL                                                 ~7
         20        DO_ICALL                                         $8      
         21        CONCAT                                           ~9      $8, '+aligned+'
         22        FETCH_DIM_R                                      ~10     !0, 2
         23        CONCAT                                           ~11     ~9, ~10
         24        CONCAT                                           ~12     ~11, '+of+'
         25        FETCH_DIM_R                                      ~13     !0, 1
         26        CONCAT                                           ~14     ~12, ~13
         27        CONCAT                                           ~15     ~14, '+yields+'
         28        INIT_FCALL                                               'date'
         29        SEND_VAL                                                 'r'
         30        INIT_FCALL                                               'align_timestamp_to'
         31        FETCH_DIM_R                                      ~16     !0, 0
         32        SEND_VAL                                                 ~16
         33        FETCH_DIM_R                                      ~17     !0, 1
         34        SEND_VAL                                                 ~17
         35        FETCH_DIM_R                                      ~18     !0, 2
         36        SEND_VAL                                                 ~18
         37        DO_FCALL                                      0  $19     
         38        SEND_VAR                                                 $19
         39        DO_ICALL                                         $20     
         40        CONCAT                                           ~21     ~15, $20
         41        CONCAT                                           ~22     ~21, '%3Cbr%2F%3E'
         42        ECHO                                                     ~22
   17    43      > JMP                                                      ->15
         44    >   FE_FREE                                                  $6
   19    45      > RETURN                                                   1

Function align_timestamp_to:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/WKOP1
function name:  align_timestamp_to
number of ops:  18
compiled vars:  !0 = $stamp, !1 = $unit, !2 = $past, !3 = $modes, !4 = $offset, !5 = $new
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
    6     3        BIND_STATIC                                              !3
   11     4        FETCH_DIM_R                                      ~6      !3, !1
          5        ASSIGN                                                   !4, ~6
   12     6        IS_EQUAL                                                 !2, 'end'
          7      > JMPZ                                                     ~8, ->12
          8    >   CONCAT                                           ~9      '%2B1+', !1
          9        CONCAT                                           ~10     ~9, '+'
         10        CONCAT                                           ~11     ~10, !4
         11        ASSIGN                                                   !4, ~11
   13    12    >   INIT_FCALL                                               'strtotime'
         13        SEND_VAR                                                 !4
         14        SEND_VAR                                                 !0
         15        DO_ICALL                                         $13     
         16        ASSIGN                                                   !5, $13
   14    17      > RETURN                                                   null

End of function align_timestamp_to

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
178.49 ms | 1403 KiB | 18 Q