3v4l.org

run code in 300+ PHP versions simultaneously
<?php function last_monday($date) { if (!is_numeric($date)) $date = strtotime($date); if (date('w', $date) == 1) return $date; else return strtotime( 'last monday', $date ); } echo date('m/d/y', last_monday('8/14/2012')); // 8/13/2012 (tuesday gives us the previous monday) echo date('m/d/y', last_monday('8/13/2012')); // 8/13/2012 (monday throws back that day) echo date('m/d/y', last_monday('8/12/2012')); // 8/06/2012 (sunday goes to previous week)
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/llKWe
function name:  (null)
number of ops:  25
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   INIT_FCALL                                               'date'
          1        SEND_VAL                                                 'm%2Fd%2Fy'
          2        INIT_FCALL                                               'last_monday'
          3        SEND_VAL                                                 '8%2F14%2F2012'
          4        DO_FCALL                                      0  $0      
          5        SEND_VAR                                                 $0
          6        DO_ICALL                                         $1      
          7        ECHO                                                     $1
   15     8        INIT_FCALL                                               'date'
          9        SEND_VAL                                                 'm%2Fd%2Fy'
         10        INIT_FCALL                                               'last_monday'
         11        SEND_VAL                                                 '8%2F13%2F2012'
         12        DO_FCALL                                      0  $2      
         13        SEND_VAR                                                 $2
         14        DO_ICALL                                         $3      
         15        ECHO                                                     $3
   16    16        INIT_FCALL                                               'date'
         17        SEND_VAL                                                 'm%2Fd%2Fy'
         18        INIT_FCALL                                               'last_monday'
         19        SEND_VAL                                                 '8%2F12%2F2012'
         20        DO_FCALL                                      0  $4      
         21        SEND_VAR                                                 $4
         22        DO_ICALL                                         $5      
         23        ECHO                                                     $5
         24      > RETURN                                                   1

Function last_monday:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/llKWe
function name:  last_monday
number of ops:  24
compiled vars:  !0 = $date
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        INIT_FCALL                                               'is_numeric'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4        BOOL_NOT                                         ~2      $1
          5      > JMPZ                                                     ~2, ->10
    4     6    >   INIT_FCALL                                               'strtotime'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $3      
          9        ASSIGN                                                   !0, $3
    5    10    >   INIT_FCALL                                               'date'
         11        SEND_VAL                                                 'w'
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                         $5      
         14        IS_EQUAL                                                 $5, 1
         15      > JMPZ                                                     ~6, ->18
    6    16    > > RETURN                                                   !0
         17*       JMP                                                      ->23
    8    18    >   INIT_FCALL                                               'strtotime'
    9    19        SEND_VAL                                                 'last+monday'
   10    20        SEND_VAR                                                 !0
         21        DO_ICALL                                         $7      
         22      > RETURN                                                   $7
   12    23*     > RETURN                                                   null

End of function last_monday

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.27 ms | 1403 KiB | 22 Q