faqts : Computers : Programming : Languages : PHP : kms

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

55 of 74 people (74%) answered Yes
Recently 10 of 10 people (100%) answered Yes

Entry

How does one create a 3d array; (continent-array(country-array(city-array)))?

Oct 2nd, 2002 09:01
Marti, Greg Billock, Paul Routledge, unknown unknown, http://www.php.net/manual/language.types.array.php


The PHP manual gives instructions on this. You can create 
multi-dimensional arrays in several ways.

1. Direct assignment: just put values into the 3-D array. PHP figures 
out what the dimensions are, keeps track of them for you. i.e.

   $places["Asia"]["China"]["Beijing"] = "latitude,longitude";
   $places["Europe"]["England"]["London"] = "xxx,yyy";
   $places["Asia"]["Japan"]["Tokyo"] = "something";

and so on.

2. Create the sub-arrays in one giant statement. Like this:

   $places = array(
      "Asia" = array(
          "China" = array(
             "Beijing" => "latitude,longitude"
          ),
          "Japan" = array(
             "Tokyo" => "something"
          )
      ),
      "Europe" = array(
          "England" = array(
             "London" => "xxx,yyy"
          )
      )
   );

Be sure to check the usage of commas, since that can often produce 
problems, if mispaced