3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = [ 'foo.bar', 'foo.bar.baz', 'foo.bar.qux', 'foo.qux', 'foo.quux', 'bar.baz', 'bar.qux', 'qux.quux', ]; $output=[]; foreach ($input as $line){ $keys = explode('.',$line); //break each section into a key $val = true; //holds next value to add to array $localArray = []; //holds the array for this input line for($i=count($keys)-1; $i>=0; $i--){ //go in reverse order $localArray = [$keys[$i]=>$val]; //store previous value in array $val = $localArray; //store the array we just built. it will be //the value of the next key } $output = array_merge_recursive($output,$localArray); } print_r($output);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [foo] => Array ( [bar] => Array ( [0] => 1 [baz] => 1 [qux] => 1 ) [qux] => 1 [quux] => 1 ) [bar] => Array ( [baz] => 1 [qux] => 1 ) [qux] => Array ( [quux] => 1 ) )

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