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



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to