3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 'Name/First' => 'John', 'Name/Last' => 'Doe', 'Age' => 20, 'Address/Postal/City' => 'New York', 'Address/Postal/Zip' => 10003, 'Address/Billing/City' => 'Los Angeles', 'Phone' => 123456789, 'Foo/Bar' => 'test1', 'Foo/Bar/Foo2/Bar2' => 'test2', ]; $newarray = []; foreach($array as $path => $value) { $keys = array_filter(explode('/', $path)); $ref = &$newarray; foreach($keys as $level => $key) { if (!array_key_exists($key, $ref)) $ref[$key] = []; $ref = &$ref[$key]; if (isset($ref) && !is_array($ref)) { break; } } if (is_array($ref)) { $ref = $value; } } print_r($newarray);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [Name] => Array ( [First] => John [Last] => Doe ) [Age] => 20 [Address] => Array ( [Postal] => Array ( [City] => New York [Zip] => 10003 ) [Billing] => Array ( [City] => Los Angeles ) ) [Phone] => 123456789 [Foo] => Array ( [Bar] => test1 ) )

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