3v4l.org

run code in 300+ PHP versions simultaneously
<?php $teams = [ 1 => [ 'AREA I' => [ 'blue' => 30, 'green' => 25, ], 'AREA II' => [ 'blue' => 15, ], ], 2 => [ 'AREA I' => [ 'blue' => 40, ], ], ]; $filterSets = [ [], [1], [2], [null, 'AREA I'], [null, 'AREA II'], [null, null, 'blue'], [null, null, 'green'], [null, 'AREA I', 'blue'], ['foo'], [null, null, null, null], ]; function sumViaPath(array $array, array $path): int { $sum = 0; $filterKey = $path ? array_shift($path) : null; foreach ($array as $k => $v) { if ($filterKey === null || $filterKey === $k) { $sum += is_array($v) ? sumViaPath($v, $path) : $v; } } return $sum; } foreach ($filterSets as $path) { $results[json_encode($path)] = sumViaPath($teams, $path); } var_export($results);
Output for git.master, git.master_jit, rfc.property-hooks
array ( '[]' => 110, '[1]' => 70, '[2]' => 40, '[null,"AREA I"]' => 95, '[null,"AREA II"]' => 15, '[null,null,"blue"]' => 85, '[null,null,"green"]' => 25, '[null,"AREA I","blue"]' => 70, '["foo"]' => 0, '[null,null,null,null]' => 110, )

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:
40.62 ms | 1018 KiB | 4 Q