3v4l.org

run code in 500+ PHP versions simultaneously
<?php $counts = [ "900,google.com", "60,mail.yahoo.com", "10,mobile.sports.yahoo.com", "40,sports.yahoo.com", "300,yahoo.com", "10,stackoverflow.com", "20,overflow.com", "5,com.com", "2,en.wikipedia.org", "1,m.wikipedia.org", "1,mobile.sports", "1,google.co.uk" ]; function calculateClicksByDomain($dataLines) { $output = []; foreach ($dataLines as $dataLine) { [$count, $domain] = explode(',', $dataLine); $nameParts = []; foreach (array_reverse(explode('.', $domain)) as $namePart) { array_unshift($nameParts, $namePart); $domain = implode('.', $nameParts); $output[$domain] = ($output[$domain] ?? 0) + $count; } } return $output; } print_r(calculateClicksByDomain($counts));
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [com] => 1345 [google.com] => 900 [yahoo.com] => 410 [mail.yahoo.com] => 60 [sports.yahoo.com] => 50 [mobile.sports.yahoo.com] => 10 [stackoverflow.com] => 10 [overflow.com] => 20 [com.com] => 5 [org] => 3 [wikipedia.org] => 3 [en.wikipedia.org] => 2 [m.wikipedia.org] => 1 [sports] => 1 [mobile.sports] => 1 [uk] => 1 [co.uk] => 1 [google.co.uk] => 1 )

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:
48.03 ms | 905 KiB | 4 Q