[SOLVED] array and array keys
05-05-08, 01:39 AM
Newbie Coder
Join Date: Oct 2007
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] array and array keys
i have this array
PHP Code:
$fileArray = array(
'WAP' => array(
'Errors.class.php' ,
'Index.class.php' ,
'Signup.class.php' ,
'Login.class.php' ,
'Home.class.php'
),
'MOB' => array(
'Errors.class.php' ,
'Index.class.php' ,
'Signup.class.php' ,
'Login.class.php' ,
'Home.class.php'
),
'WEB' => array(
'Errors.class.php' ,
'Index.class.php' ,
'Signup.class.php' ,
'Login.class.php' ,
'Home.class.php'
)
);
this function
which will return WAP MOB or WEB depending on the browser.
i want to include the files in the arrays in a loop if the array key == the value returned from the function to check browser. how do ii go about doing this?
your help will be really appreciated.
05-05-08, 02:06 AM
Newbie Coder
Join Date: Oct 2007
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
never mind
never mind i figured it out
05-05-08, 02:33 AM
Community Leader
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
This could be simplified a bit:
05-05-08, 02:50 AM
Newbie Coder
Join Date: Oct 2007
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by
Nico
This could be simplified a bit:
that didnt seem to work but this gets it done
thanks anyway
05-05-08, 02:55 AM
Community Leader
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Maybe 'cause I forgot to add the $sources_dir to the include().
05-05-08, 03:11 AM
Newbie Coder
Join Date: Oct 2007
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
i'm looking for an easier way to do this
PHP Code:
// Gets $ac or set to 'index' if not defined
$ac = isset( $_REQUEST [ 'ac' ]) ? $_REQUEST [ 'ac' ] : 'index' ;
// $REQUEST['ac']array - $REQUEST['ac']=>array('class','method');
if( $func -> checkBrowser ()== 'MOB' ) // set mobile array else set other array
{
$acArray = array(
'index' => array(
'Index' , 'display'
),
'signup' => array(
'Signup' , 'display'
),
'login' => array(
'Login' , 'display'
),
'home' => array(
'Home' , 'display'
)
);
}else if( $func -> checkBrowser ()== 'WAP' ) //set wap array
{
$acArray = array(
'index' => array(
'Index' , 'display'
),
'signup' => array(
'Signup' , 'display'
),
'login' => array(
'Login' , 'display'
),
'home' => array(
'Home' , 'display'
)
);
}else{
//other/web array
$acArray = array(
'index' => array(
'Index' , 'display'
),
'signup' => array(
'Signup' , 'display'
),
'login' => array(
'Login' , 'display'
),
'home' => array(
'Home' , 'display'
)
);
}
// Checks if the array key (action request)($REQUEST['ac']) is in $acArray
if(! array_key_exists ( $ac , $acArray ))
{
$Errors -> PGerror ();
exit();
}
// Creates object
$Object = new $acArray [ $ac ][ 0 ];
// Instance of object
$Object -> $acArray [ $ac ][ 1 ]();
can you assist me please
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off