3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = '[ { "date": "2022-02-15", "websites": [ { "website_name": "instagram", "num_followers": "123146780" }, { "website_name": "instagram", "num_followers": "123134954" }, { "website_name": "tiktok", "num_followers": "123184229" } ] }, { "date": "2022-02-14", "websites": [ { "website_name": "instagram", "num_followers": "123057832" }, { "website_name": "tiktok", "num_followers": "123058141" }, { "website_name": "tiktok", "num_followers": "123058219" }, { "website_name": "instagram", "num_followers": "123059280" } ] } ]'; $data = []; foreach (json_decode($input, true) as $day) { $items['date'] = $day['date']; $sites = []; foreach ($day['websites'] as $site) { $name = $site['website_name']; if (key_exists($name, $sites) === false) { $sites[$name] = $site; continue; } if ($sites[$name]['num_followers'] < $site['num_followers']) { $sites[$name] = $site; } } $items['websites'] = array_values($sites); $data[] = $items; } var_dump(json_encode($data, JSON_PRETTY_PRINT));
Output for git.master, git.master_jit, rfc.property-hooks
string(620) "[ { "date": "2022-02-15", "websites": [ { "website_name": "instagram", "num_followers": "123146780" }, { "website_name": "tiktok", "num_followers": "123184229" } ] }, { "date": "2022-02-14", "websites": [ { "website_name": "instagram", "num_followers": "123059280" }, { "website_name": "tiktok", "num_followers": "123058219" } ] } ]"

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