3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ (object) ['id' => 1, 'category' => 'Pizza', 'product' => 'Large Pizza', 'complement_type' => 'Bread', 'option' => 'Brown bread'], (object) ['id' => 2, 'category' => 'Pizza', 'product' => 'Small Pizza', 'complement_type' => 'Bread', 'option' => 'White bread'], (object) ['id' => 3, 'category' => 'Pizza', 'product' => 'Small Pizza', 'complement_type' => 'Ingredients', 'option' => 'Olives'], (object) ['id' => 4, 'category' => 'Salads', 'product' => 'Green Salad', 'complement_type' => 'Extras', 'option' => 'Bacon'], (object) ['id' => 5, 'category' => 'Salads', 'product' => 'Cesars Salad', 'complement_type' => 'Extras', 'option' => 'Lettuce'], ]; $result = []; foreach ($array as $obj) { $result[$obj->category][$obj->product][$obj->complement_type] = $obj->option; } var_export($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:
62.56 ms | 406 KiB | 5 Q