3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = array ( '2014-04-22|Paul' => 0, '2014-04-28|Paul' => 2, '2014-05-13|Paul' => 0, '2014-06-03|Paul' => 1, '2014-06-12|Paul' => 0, '2014-08-11|Paul' => 1, '2014-08-28|Paul' => 3, '2012-05-09|John' => 1, '2012-08-29|John' => 2, '2012-09-05|John' => 0, '2012-09-13|John' => 1 ); $b = array(); $lastname = ''; foreach ($a as $key => $value) { list($d, $n) = explode('|', $key); if ($n == $lastname) { $total += $value; } else { $total = $value; } $b[$key] = $total; $lastname = $n; } print_r($b);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [2014-04-22|Paul] => 0 [2014-04-28|Paul] => 2 [2014-05-13|Paul] => 2 [2014-06-03|Paul] => 3 [2014-06-12|Paul] => 3 [2014-08-11|Paul] => 4 [2014-08-28|Paul] => 7 [2012-05-09|John] => 1 [2012-08-29|John] => 3 [2012-09-05|John] => 3 [2012-09-13|John] => 4 )

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:
54.6 ms | 401 KiB | 8 Q