3v4l.org

run code in 300+ PHP versions simultaneously
<?php $items = array( array("itemName" => "Hat", "price" => 10.99, "categories" => ["apparel", "head"]), array("itemName" => "Scarf", "price" => 7.99, "categories" => ["apparel", "neck"]), array("itemName" => "Watch", "price" => 19.99, "categories" => ["jewelry", "electronics"]), array("itemName" => "Necklace", "price" => 99.99, "categories" => ["jewelry", "neck"]), array("itemName" => "Headphones", "price" => 29.99, "categories" => ["head", "electronics"]) ); foreach (array_unique(array_merge(...array_values(array_column($items, 'categories')))) as $value) { foreach ($items as $item) { if (in_array($value, $item['categories'])) { $categories[$value][] = $item['itemName']; } } } print_r($categories);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [apparel] => Array ( [0] => Hat [1] => Scarf ) [head] => Array ( [0] => Hat [1] => Headphones ) [neck] => Array ( [0] => Scarf [1] => Necklace ) [jewelry] => Array ( [0] => Watch [1] => Necklace ) [electronics] => Array ( [0] => Watch [1] => Headphones ) )

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:
179.31 ms | 406 KiB | 5 Q