[ create a new paste ] login | about

Link: http://codepad.org/6i6wWMNI    [ raw code | output | fork ]

PHP, pasted on May 12:
<?php

$results = array(
	array(
		'Location' => 'Vancouver',
		'Region' => 'British Columbia',
		'Country' => 'Canada'
	),
	array(
		'Location' => 'New Market',
		'Region' => 'Ontario',
		'Country' => 'Canada'
	),
	array(
		'Location' => 'Barrie',
		'Region' => 'Ontario',
		'Country' => 'Canada'
	),
	array(
		'Location' => 'New York City',
		'Region' => 'New York',
		'Country' => 'US'
	)
);

$i = 0;

while ($i < count($results)) {
	$currentCountry = $results[$i]['Country'];
	echo "-" . $currentCountry . PHP_EOL;

	while ($results[$i]['Country'] == $currentCountry) {
		$currentRegion = $results[$i]['Region'];
		echo "--" . $currentRegion . PHP_EOL;

		while ($results[$i]['Region'] == $currentRegion) {
			echo "---" . $results[$i]['Location'] . PHP_EOL;
			$i++;
			if ($i == count($results)) break;
		}

		if ($i == count($results)) break;		
	}	
}


Output:
1
2
3
4
5
6
7
8
9
-Canada
--British Columbia
---Vancouver
--Ontario
---New Market
---Barrie
-US
--New York
---New York City


Create a new paste based on this one


Comments: