Tutorial 8: Multi-Dimensional Arrays

This is where we start getting crazy! We can harness the true potential of arrays by using multi-dimensional arrays — which is simply an array that is comprised of multiple arrays!

$moustaches = array (

					array (
						"name"				=> "Handlebar",
						"creep_factor"		=> "High",
						"avg_growth_days"	=> 14
					array (
						"name"				=> "Salvador Dali",
						"creep_factor"		=> "Extreme",
						"avg_growth_days"	=> 62
					array (
						"name"				=> "Fu Manchu",
						"creep_factor"		=> "Very High",
						"avg_growth_days"	=> 58


You're probably wondering how the heck we display this info on the screen! Well, we first have to reference the parent array $moustaches, then the numerical value of the child array (Handlebar is [0], Salvador Dali [1], etc), and finally the custom key of the information we want to display (name, creep_factor, etc). It looks like this:

<?php echo $moustaches[2]["name"]; ?>

The above code will display Fu Manchu.

Check out the final example
©2019 Brad Hussey