3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data[2020] = array_fill_keys(range(1,12), '1,000'); $data[2021] = array_fill_keys(range(1,8), '1,500'); $data[2021][9] = null; $data[2021][10] = null; $data[2021][11] = null; $data[2021][12] = null; $thisYear = $year ?? date('Y'); $lastYear = $thisYear - 1; $thisYearRunningTotal = 0; $lastYearRunningTotal = 0; $result = []; for ($month = 1; $month <= 12; ++$month) { $thisYearMonthTotal = $data[$thisYear][$month]; // from model $thisYearRunningTotal = $thisYearMonthTotal === null ? null : (int)str_replace(',', '', $thisYearMonthTotal) + $thisYearRunningTotal; $lastYearMonthTotal = $data[$lastYear][$month]; // from model $lastYearRunningTotal = $lastYearMonthTotal === null ? null : (int)str_replace(',', '', $lastYearMonthTotal) + ($lastYearRunningTotal ?? 0); $result[] = [ 'month' => $month, 'total_now' => $thisYearRunningTotal, 'total_before' => $lastYearRunningTotal, ]; } var_export($result);
Output for git.master, git.master_jit, rfc.property-hooks
array ( 0 => array ( 'month' => 1, 'total_now' => 1500, 'total_before' => 1000, ), 1 => array ( 'month' => 2, 'total_now' => 3000, 'total_before' => 2000, ), 2 => array ( 'month' => 3, 'total_now' => 4500, 'total_before' => 3000, ), 3 => array ( 'month' => 4, 'total_now' => 6000, 'total_before' => 4000, ), 4 => array ( 'month' => 5, 'total_now' => 7500, 'total_before' => 5000, ), 5 => array ( 'month' => 6, 'total_now' => 9000, 'total_before' => 6000, ), 6 => array ( 'month' => 7, 'total_now' => 10500, 'total_before' => 7000, ), 7 => array ( 'month' => 8, 'total_now' => 12000, 'total_before' => 8000, ), 8 => array ( 'month' => 9, 'total_now' => NULL, 'total_before' => 9000, ), 9 => array ( 'month' => 10, 'total_now' => NULL, 'total_before' => 10000, ), 10 => array ( 'month' => 11, 'total_now' => NULL, 'total_before' => 11000, ), 11 => array ( 'month' => 12, 'total_now' => NULL, 'total_before' => 12000, ), )

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:
341.59 ms | 409 KiB | 5 Q