Page 1 of 1

array issues

Posted: Mon May 21, 2007 1:35 am
by kcpaige89
I have an array that will have several possiblities, such as a1-a12 and b1-b48 and c1-c128 yadda yadda.

My question would be, if each of these represents a different unique index.html file in a seperate directory,

ie, ./this/place/b1/index.html + /this/place/b2/index.html
but /that/place/a1/index.html

so, all the b numbers are found in /this/place/ and all the a numbers are found in /that/place/

is there a way to make a switch statement include that file?

my psedo-code

Code: Select all

$some_value = the desired page, such as a11
switch (array($some_value)){
        case array(any a number value):

        include ("/that/place/any a number value/index.html");
        break;

        case array(any b number value):
        include ("/this/place/any b number value/index.html");
        break;
}
the goal of this is to avoid several hundred switch cases, like a case for a1 a2 a3 a4 and so on.

Posted: Mon May 21, 2007 2:58 am
by bdlang
Is the actual array index a1, a2 and so on?

Or is it more like

Code: Select all

Array (
    0 => 'a1',
    2 => 'a2',
    3 => 'a4',
    etc
)
If that's the case, I would populate my array differently so as to avoid a switch altogether, e.g.

Code: Select all

Array (
    'a1' => 0,
    'a2' => 0,
    ....
    'c5' => 0,
    etc
)
This way you can do a simple isset() and then check for the directory / file, e.g.

Code: Select all

$some_value = 'a11';
if ( isset($array[$some_value]) && is_dir("/that/place/{$some_value}")  ) {
    include_once("/that/place/{$some_value}/index.html");
}
That's it, 1 line.