3v4l.org

run code in 300+ PHP versions simultaneously
<?php $j = <<<EOD [{"id": 1, "product": {"id": 1, "brand": {"id": 1, "name": "iphone"}}, "provider": {"id": 1, "name": "at&t"}}, {"id": 2, "product": {"id": 2, "brand": {"id": 2, "name": "iphone"}}, "provider": {"id": 1, "name": "at&t"}}, {"id": 3, "product": {"id": 3, "brand": {"id": 3, "name": "iphone"}}, "provider": {"id": 1, "name": "t-mobile"}}] EOD; $items = json_decode($j); $tm = array(); foreach ($items as $item) { $product = $item->product->brand->name; $provider = $item->provider->name; $tm[$provider][$product] = ($tm[$provider][$product] ?? 0) + 1; } print_r($tm);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [at&t] => Array ( [iphone] => 2 ) [t-mobile] => Array ( [iphone] => 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:
35.99 ms | 405 KiB | 5 Q