3v4l.org

run code in 300+ PHP versions simultaneously
<?php const URLS = [ "http://site.com/", "http://site.com/save", "http://site.com/save/results", "http://site.com/save/results/path", "http://site.com/path/save/results", "http://site.com/save/path", "http://site.com/path/results", "http://site.com/Crawler4", "http://site.com/Crawler", ]; $siteStructure = []; foreach (URLS as $url) { // Parse the URL into components ['scheme' => $scheme, 'host' => $host, 'path' => $path] = parse_url($url); // build the slug for the top-level element $realm = $scheme . '://' . $host; // create the top levekl element and get a reference to it $siteStructure[$realm] = $siteStructure[$realm] ?? []; $current = &$siteStructure[$realm]; // parse the path into parts $pathEls = preg_split('/[^a-zA-Z0-9]+/', $path, 0, PREG_SPLIT_NO_EMPTY); foreach ($pathEls as $el) { // for each part, make sure the child array exists and overwrite the reference to the child $current[$el] = $current[$el] ?? []; $current = &$current[$el]; } $current[0] = $url; // delete the reference at the end of the loop to prevent accidents unset($current); } var_dump($siteStructure);
Output for git.master, git.master_jit, rfc.property-hooks
array(1) { ["http://site.com"]=> array(5) { [0]=> string(16) "http://site.com/" ["save"]=> array(3) { [0]=> string(20) "http://site.com/save" ["results"]=> array(2) { [0]=> string(28) "http://site.com/save/results" ["path"]=> array(1) { [0]=> string(33) "http://site.com/save/results/path" } } ["path"]=> array(1) { [0]=> string(25) "http://site.com/save/path" } } ["path"]=> array(2) { ["save"]=> array(1) { ["results"]=> array(1) { [0]=> string(33) "http://site.com/path/save/results" } } ["results"]=> array(1) { [0]=> string(28) "http://site.com/path/results" } } ["Crawler4"]=> array(1) { [0]=> string(24) "http://site.com/Crawler4" } ["Crawler"]=> array(1) { [0]=> string(23) "http://site.com/Crawler" } } }

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:
61.89 ms | 403 KiB | 8 Q