3v4l.org

run code in 300+ PHP versions simultaneously
<?php $locations = [ ['country'=>'USA', 'state'=>'New York', 'city'=>'NYC', 'location'=>'Central Park', 'street'=>'7th Ave', 'count'=>123], ['country'=>'USA', 'state'=>'Maryland', 'city'=>'Baltimore', 'location'=>'Harber', 'count'=>24], ['country'=>'USA', 'state'=>'Michigan', 'city'=>'Lansing', 'location'=>'Midtown', 'building'=>'H2B', 'count'=>7], ['country'=>'France', 'state'=>'Sud', 'city'=>'Marseille', 'location'=>'Centre Ville', 'count'=>12], ]; $hierarchy = array(); $levels = array_reverse( array('country', 'state', 'city', 'location') ); $lastLevel = 'count'; foreach ( $locations as $L ) { $array = $L[$lastLevel]; foreach ( $levels as $level ) { $array = array($L[$level] => $array); } $hierarchy = array_merge_recursive($hierarchy, $array); } print_r($hierarchy);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [USA] => Array ( [New York] => Array ( [NYC] => Array ( [Central Park] => 123 ) ) [Maryland] => Array ( [Baltimore] => Array ( [Harber] => 24 ) ) [Michigan] => Array ( [Lansing] => Array ( [Midtown] => 7 ) ) ) [France] => Array ( [Sud] => Array ( [Marseille] => Array ( [Centre Ville] => 12 ) ) ) )

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