3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getTimeRange($month) { $month = str_pad($month, 2, '0', STR_PAD_LEFT); $year = $month > date('m') ? date('Y') - 1 : date('Y'); $start_date = "{$year}-{$month}-01"; $end_date = date('Y-m-d', strtotime("+1 month", strtotime($start_date))); return array( 'start_date' => $start_date, 'end_date' => $end_date ); } function getTimeRange2($month, $year = 0) { $month = str_pad($month, 2, '0', STR_PAD_LEFT); $year = ($year ? : ($month > date('m') ? date('Y') - 1 : date('Y'))); $res = array( 'start_date' => "{$year}-{$month}-01", 'end_date' => date('Y-m-d', strtotime("+1 month", strtotime($res['start_date']))) ); return $res; } var_dump(getTimeRange(1)); var_dump(getTimeRange2(1));
Output for git.master, git.master_jit
array(2) { ["start_date"]=> string(10) "2017-01-01" ["end_date"]=> string(10) "2017-02-01" } Warning: Undefined variable $res in /in/Z68l9 on line 20 Warning: Trying to access array offset on value of type null in /in/Z68l9 on line 20 Deprecated: strtotime(): Passing null to parameter #1 ($datetime) of type string is deprecated in /in/Z68l9 on line 20 array(2) { ["start_date"]=> string(10) "2017-01-01" ["end_date"]=> string(10) "1970-02-01" }
Output for rfc.property-hooks
array(2) { ["start_date"]=> string(10) "2017-01-01" ["end_date"]=> string(10) "2017-02-01" } Warning: Undefined variable $res in /in/Z68l9 on line 20 Warning: Trying to access array offset on null in /in/Z68l9 on line 20 Deprecated: strtotime(): Passing null to parameter #1 ($datetime) of type string is deprecated in /in/Z68l9 on line 20 array(2) { ["start_date"]=> string(10) "2017-01-01" ["end_date"]=> string(10) "1970-02-01" }

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:
66.3 ms | 402 KiB | 8 Q