Use arrays in php for mapping values ​​to keys. Typically, the application fields of an array are used to create a list (vector), hash table, or a dictionary, collection, stack or queue. Interestingly, the array function offers the possibility nest arrays as trees.

In a stacked or recursive array, also called a a multidimensional array, you can group information level by level. To get data you walk down the recursively tree step by step. Three examples fo nested arrays are listed here. Since few good examples could be found on StackOverflow, I’ve complied a brief comparison here.

Classic array

// Simple Array

$thearray1 = (object) array(
	'oi' => 'io',
	'ui' => 'iu',
	'mi' => 'im' // Thats the item we want to fetch
	);

echo $thearray1->mi;

Output: “im”

Recursive array php example 1


// Recursive Array
echo "</br>";


$thearray2 = (object) array(
	'oi' => 'io',
	'ui' => 'iu',
	'mi' => (object) array (
		'ma' => 'am', // Thats the item we want to fetch
		'mo' => 'om', 
		'me' => 'em')
	);

echo $thearray2->mi->ma;

Output: “am”

Recursive array php example 2

// Multiple-Recursive Arrays
echo "</br>";

$thearray3 = (object) array(
	'oi' => 'io',
	'ui' => 'iu',
	
	'mi' => (object) array (
		'ma' => 'am',
		'mo' => 'om',
		'me' => 'em',
		
		'mu' => (object) array (
			'us' => 'su',
			'un' => 'nu',
			'ul' => 'lu') // Item we want to fetch

		)
		
	);

echo $thearray3->mi->mu->ul;

Output: “lu”

Get the Example here on GitHub