Re: multidemention array question(s)

From: Date: Fri, 19 Jan 2001 18:55:46 +0000
Subject: Re: multidemention array question(s)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-35688@lists.php.net to get a copy of this message
On Fri, 19 Jan 2001, Michael Zornek wrote: > ok so i set up a multidimensional array with the following code: > > <?PHP > // departments.inc > // > // This file defines the switches. All the forms, and return displays are > // based on this table (multidimential array). The first index is the > switch number, > // then each department has three proporties. > // 1, Can the website use this depatement? > // 2, Can this department be used in the admin pages? > // 3, Its name. > $departments = array ("s1" => array("On", "On", "The > Seybold Report"), > "s2" => array("On", "On", "Publishing Systems"), > "s3" => array("On", "On", "Internet Publishing"), > "s4" => array("On", "On", "The Bulletin"), > "s5" => array("Off", "Off", ""), (snip) > Now I am creating forms and tables and need to retrieve this info I'd > like to say something like: > > if switch s23 is availbe to the admin pages do this, else do that. if ($departments['s23'][1] == 'On') // This department can be used in the admin pages else // Not > echo switch 34's name echo $departments['s34'][2] If you wanted to make the code a bit more intuitive, you could reconstruct the array to have string keys: $departments = Array( 's1' => Array('live' => 1, 'admin' => 1, 'name' => "Dept's Name"), 's2' => Array('live' => 0, 'admin' => 1, 'name' => ''), and so on ); At this point, you can simply check if a department is live or admin available with a boolean, and later on people who look at the code won't have to wonder what the array field $departments['s23'][1] contains. if ($departments['s23']['admin']) // This department can be used in the admin pages else // Not echo $departments['s34']['name'] Matt

« previous php.general (#35688) next »