3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Info { public function __construct(public int $count) {} } $ballsToDolls = [1 => [11 => new Info(3), 22 => new Info(4)], 2 => [22 => new Info(5), 44 => new Info(6)]]; print_r($ballsToDolls); $data = []; foreach ($ballsToDolls as $ballId => $dolls) { foreach ($dolls as $dollId => $info) { $data[$ballId][$dollId] = ($data[$ballId][$dollId] ?? 0) + $info->count; } } print_r($data); $data = $ballsToDolls; array_walk_recursive($data, static function(&$item, $key) { $item = $item instanceof Info ? $item->count : $item; }); print_r($data);
Output for git.master_jit, git.master
Array ( [1] => Array ( [11] => Info Object ( [count] => 3 ) [22] => Info Object ( [count] => 4 ) ) [2] => Array ( [22] => Info Object ( [count] => 5 ) [44] => Info Object ( [count] => 6 ) ) ) Array ( [1] => Array ( [11] => 3 [22] => 4 ) [2] => Array ( [22] => 5 [44] => 6 ) ) Array ( [1] => Array ( [11] => 3 [22] => 4 ) [2] => Array ( [22] => 5 [44] => 6 ) )

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