How to create multi dimensional array in php

0 votes
asked Jun 12, 2013 in Php by anonymous
retagged Jun 12, 2013 by administrator

In what scenario I may need multi dimentaional array in php? Please post me some sample code and help me understand how it works?

Share

1 Answer

0 votes
answered Jun 12, 2013 by administrator (315 points)
selected Jun 30, 2013 by administrator
 
Best answer

Creating multi dimensional array is very easy and it is same as creating single dimensional array. Because array can hold any type of object. It could be primitives or it could custom objects. So, it can hold another array as well.

Example two dimensional array:

$_MultiDimensionalArray = array("Microsoft" => array("C#.NET", "VB.NET", "ASP.NET"),
"Google"=> array("Analytics", "Cloud", "BigQuery"));
echo $_MultiDimensionalArray["Microsoft"][0];
echo $_MultiDimensionalArray["Google"][1];

above code will print "C#.NET" and "Cloud". Using the same idea, we can create 3 dimensional array also.

Your answer

Preview

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
site design / logo / content © 2013 - 2015 pinfaq.com
...