3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ "Jan 2016" => 2, "Feb 2016" => 4, "Mar 2016" => 2, "Apr 2016" => 0, "Jan 2017" => 9, "Feb 2017" => 2, "Mar 2017" => 5, "Jan 2018" => 4, "Feb 2018" => 6 ]; foreach ($array as $date => &$amount) { $year = substr($date, -4); $amount = ['month' => $amount, 'total' => &$ref[$year]]; $ref[$year] = ($ref[$year] ?? 0) + $amount['month']; } var_export($array);
Output for git.master, git.master_jit, rfc.property-hooks
array ( 'Jan 2016' => array ( 'month' => 2, 'total' => 8, ), 'Feb 2016' => array ( 'month' => 4, 'total' => 8, ), 'Mar 2016' => array ( 'month' => 2, 'total' => 8, ), 'Apr 2016' => array ( 'month' => 0, 'total' => 8, ), 'Jan 2017' => array ( 'month' => 9, 'total' => 16, ), 'Feb 2017' => array ( 'month' => 2, 'total' => 16, ), 'Mar 2017' => array ( 'month' => 5, 'total' => 16, ), 'Jan 2018' => array ( 'month' => 4, 'total' => 10, ), 'Feb 2018' => array ( 'month' => 6, 'total' => 10, ), )

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:
58.2 ms | 407 KiB | 5 Q