3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 'Spain' => [ 'Barcelona' => 2, 'Madrid' => 4, 'Mallorca' => 10, ], 'France' => [ 'Paris' => 1, 'Monaco' => 3, ], ]; $output = []; foreach ($array as $country => $cities_points) { $count = count($cities_points); // Sum all of the values $sum = array_sum($cities_points); // Keep track of each city $items = []; foreach ($cities_points as $city => $point) { $items[] = sprintf('%1$s (%2$d)', $city, $point); } // Put it all together $output[] = sprintf('%1$s (%2$dx|%3$d) - %4$s', $country, $count, $sum, implode(', ', $items)); } echo implode(PHP_EOL, $output);
Output for git.master, git.master_jit, rfc.property-hooks
Spain (3x|16) - Barcelona (2), Madrid (4), Mallorca (10) France (2x|4) - Paris (1), Monaco (3)

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:
122.58 ms | 405 KiB | 5 Q