3v4l.org

run code in 300+ PHP versions simultaneously
<?php $jsonString = '[{"id":1,"category":"Pizza","product":"Large Pizza","complement_type":"Bread","option":"Brown bread"},{"id":2,"category":"Pizza","product":"Small Pizza","complement_type":"Bread","option":"White bread"},{"id":3,"category":"Pizza","product":"Small Pizza","complement_type":"Ingredients","option":"Olives"},{"id":4,"category":"Salads","product":"Green Salad","complement_type":"Extras","option":"Bacon"},{"id":5,"category":"Salads","product":"Cesars Salad","complement_type":"Extras","option":"Lettuce"}]'; $array = json_decode($jsonString); $result = array(); foreach ($array as $row) { if (!isset($result[$row->category])) { $result[$row->category] = array(); } if (!isset($result[$row->category][$row->product])) { $result[$row->category][$row->product] = array(); } $result[$row->category][$row->product][$row->complement_type] = $row->option; } print_r($result);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [Pizza] => Array ( [Large Pizza] => Array ( [Bread] => Brown bread ) [Small Pizza] => Array ( [Bread] => White bread [Ingredients] => Olives ) ) [Salads] => Array ( [Green Salad] => Array ( [Extras] => Bacon ) [Cesars Salad] => Array ( [Extras] => Lettuce ) ) )

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