3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Get Dates In Month. * * @updated 2022-12-15 19:09:31 +07:00 * * @param bool|string $yearmonth * true = current year/month * string = other year/month * * @note If using PHP < 8, remove the bool|string union type signature! * @return array */ function get_dates_in_month(bool|string $yearmonth): array { /* If for current year/month */ if($yearmonth === true) { $base = date('Y-m'); // Current base date $days = range(1, date('d')); // Days from 1 to now } /* If for other year/month */ else { $base = $yearmonth; // Literal base date $days = range(1, date('t', strtotime($yearmonth))); // Days from 1 to month max } /* Combine with day added */ $dates = array_map(function($day) use ($base) { return $base . '-' . str_pad((string) $day, 2, "0", STR_PAD_LEFT); }, $days); return $dates; } echo "==== Current Y/M ====\n"; var_dump(get_dates_in_month(true)); echo "==== Other Y/M ====\n"; var_dump(get_dates_in_month('1980-02'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TrTPs
function name:  (null)
number of ops:  15
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   ECHO                                                     '%3D%3D%3D%3D+Current+Y%2FM+%3D%3D%3D%3D%0A'
   37     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'get_dates_in_month'
          3        SEND_VAL                                                 <true>
          4        DO_FCALL                                      0  $0      
          5        SEND_VAR                                                 $0
          6        DO_ICALL                                                 
   39     7        ECHO                                                     '%3D%3D%3D%3D+Other+Y%2FM+%3D%3D%3D%3D%0A'
   40     8        INIT_FCALL                                               'var_dump'
          9        INIT_FCALL                                               'get_dates_in_month'
         10        SEND_VAL                                                 '1980-02'
         11        DO_FCALL                                      0  $2      
         12        SEND_VAR                                                 $2
         13        DO_ICALL                                                 
         14      > RETURN                                                   1

Function get_dates_in_month:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 16
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TrTPs
function name:  get_dates_in_month
number of ops:  40
compiled vars:  !0 = $yearmonth, !1 = $base, !2 = $days, !3 = $dates
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   19     1        TYPE_CHECK                                    8          !0
          2      > JMPZ                                                     ~4, ->16
   20     3    >   INIT_FCALL                                               'date'
          4        SEND_VAL                                                 'Y-m'
          5        DO_ICALL                                         $5      
          6        ASSIGN                                                   !1, $5
   21     7        INIT_FCALL                                               'range'
          8        SEND_VAL                                                 1
          9        INIT_FCALL                                               'date'
         10        SEND_VAL                                                 'd'
         11        DO_ICALL                                         $7      
         12        SEND_VAR                                                 $7
         13        DO_ICALL                                         $8      
         14        ASSIGN                                                   !2, $8
   19    15      > JMP                                                      ->29
   25    16    >   ASSIGN                                                   !1, !0
   26    17        INIT_FCALL                                               'range'
         18        SEND_VAL                                                 1
         19        INIT_FCALL                                               'date'
         20        SEND_VAL                                                 't'
         21        INIT_FCALL                                               'strtotime'
         22        SEND_VAR                                                 !0
         23        DO_ICALL                                         $11     
         24        SEND_VAR                                                 $11
         25        DO_ICALL                                         $12     
         26        SEND_VAR                                                 $12
         27        DO_ICALL                                         $13     
         28        ASSIGN                                                   !2, $13
   30    29    >   INIT_FCALL                                               'array_map'
         30        DECLARE_LAMBDA_FUNCTION                          ~15     [0]
         31        BIND_LEXICAL                                             ~15, !1
   32    32        SEND_VAL                                                 ~15
         33        SEND_VAR                                                 !2
   30    34        DO_ICALL                                         $16     
         35        ASSIGN                                                   !3, $16
   33    36        VERIFY_RETURN_TYPE                                       !3
         37      > RETURN                                                   !3
   34    38*       VERIFY_RETURN_TYPE                                       
         39*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TrTPs
function name:  {closure}
number of ops:  13
compiled vars:  !0 = $day, !1 = $base
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   31     2        CONCAT                                           ~2      !1, '-'
          3        INIT_FCALL                                               'str_pad'
          4        CAST                                          6  ~3      !0
          5        SEND_VAL                                                 ~3
          6        SEND_VAL                                                 2
          7        SEND_VAL                                                 '0'
          8        SEND_VAL                                                 0
          9        DO_ICALL                                         $4      
         10        CONCAT                                           ~5      ~2, $4
         11      > RETURN                                                   ~5
   32    12*     > RETURN                                                   null

End of Dynamic Function 0

End of function get_dates_in_month

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.39 ms | 1018 KiB | 21 Q