3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = Array ( 0 => 'Accessories/Apron', 1 => 'Accessories/Banners', 2 => 'Accessories/Belts', 3 => 'Brand/Brand1', 4 => 'Brand/Brand2', 5 => 'Apparel/Men/Belts', 6 => 'Apparel/Men/Socks', 7 => 'Apparel/Women/Leggings' ); $result =[]; foreach($arr as $val){ $count = count(explode("/", $val)); $str = '{"' . str_replace('/', '":{"', $val) . '"}' . str_repeat("}", $count-1); $json = preg_replace("/(.*)(\{)(.*?)(\})/", "$1[$3]", $str); $result = array_merge_recursive($result, json_decode($json, true)); } Print_r($result);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [Accessories] => Array ( [0] => Apron [1] => Banners [2] => Belts ) [Brand] => Array ( [0] => Brand1 [1] => Brand2 ) [Apparel] => Array ( [Men] => Array ( [0] => Belts [1] => Socks ) [Women] => Array ( [0] => Leggings ) ) )

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