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'));
Output for git.master, git.master_jit, rfc.property-hooks
==== Current Y/M ==== array(15) { [0]=> string(10) "2022-12-01" [1]=> string(10) "2022-12-02" [2]=> string(10) "2022-12-03" [3]=> string(10) "2022-12-04" [4]=> string(10) "2022-12-05" [5]=> string(10) "2022-12-06" [6]=> string(10) "2022-12-07" [7]=> string(10) "2022-12-08" [8]=> string(10) "2022-12-09" [9]=> string(10) "2022-12-10" [10]=> string(10) "2022-12-11" [11]=> string(10) "2022-12-12" [12]=> string(10) "2022-12-13" [13]=> string(10) "2022-12-14" [14]=> string(10) "2022-12-15" } ==== Other Y/M ==== array(29) { [0]=> string(10) "1980-02-01" [1]=> string(10) "1980-02-02" [2]=> string(10) "1980-02-03" [3]=> string(10) "1980-02-04" [4]=> string(10) "1980-02-05" [5]=> string(10) "1980-02-06" [6]=> string(10) "1980-02-07" [7]=> string(10) "1980-02-08" [8]=> string(10) "1980-02-09" [9]=> string(10) "1980-02-10" [10]=> string(10) "1980-02-11" [11]=> string(10) "1980-02-12" [12]=> string(10) "1980-02-13" [13]=> string(10) "1980-02-14" [14]=> string(10) "1980-02-15" [15]=> string(10) "1980-02-16" [16]=> string(10) "1980-02-17" [17]=> string(10) "1980-02-18" [18]=> string(10) "1980-02-19" [19]=> string(10) "1980-02-20" [20]=> string(10) "1980-02-21" [21]=> string(10) "1980-02-22" [22]=> string(10) "1980-02-23" [23]=> string(10) "1980-02-24" [24]=> string(10) "1980-02-25" [25]=> string(10) "1980-02-26" [26]=> string(10) "1980-02-27" [27]=> string(10) "1980-02-28" [28]=> string(10) "1980-02-29" }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
32.89 ms | 411 KiB | 5 Q