Aureole Posted February 8, 2008 Share Posted February 8, 2008 I want to have something like this: <?php $input = array ( 'home' => array( 'Home', 'index.php'), 'contact' => array( 'Contact', 'contact.php') ); if( in_array( $_GET['file'], $input ) ) { // Include the file here... } ?> But I'm not sure how to go about it, any ideas? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 8, 2008 Share Posted February 8, 2008 Why have a 2-d array? Do something like: <?php $input = array ( 'home' => 'index.php', 'contact' => 'contact.php' ); foreach ($input as $fld => $val) if ($_GET['file'] == $val) include($val); ?> Ken Quote Link to comment Share on other sites More sharing options...
Aureole Posted February 8, 2008 Author Share Posted February 8, 2008 Because there will be more things in the array (around 4 or 5 in total for each) than I put in my example, I just only put 2 to make it easier for people to try and help. Quote Link to comment Share on other sites More sharing options...
Barand Posted February 8, 2008 Share Posted February 8, 2008 ... I just only put 2 to make it easier for people to try and help. Didn't work though, did it? Someone helps with information given then you move the goalposts Quote Link to comment Share on other sites More sharing options...
Aureole Posted February 8, 2008 Author Share Posted February 8, 2008 You make a point, I'll be sure to keep that in mind. Quote Link to comment Share on other sites More sharing options...
Aureole Posted February 8, 2008 Author Share Posted February 8, 2008 Does anyone have any ideas on how I could approach this? Thanks. Quote Link to comment Share on other sites More sharing options...
z0mb1 Posted February 8, 2008 Share Posted February 8, 2008 I'm confused now, What is it that really want to do? As a general rule I find that there are simple workarounds to tricky ideas Quote Link to comment Share on other sites More sharing options...
laffin Posted February 8, 2008 Share Posted February 8, 2008 <?php $pages = array( 'home' => 'index.php', 'contact' => 'contact.php' ); if(isset($_GET['file']) && (array_key_exists($_GET['file'],$pages)) { include($pages[$_GET['file']); } echo "Unknown page."; ?> Quote Link to comment Share on other sites More sharing options...
Aureole Posted February 9, 2008 Author Share Posted February 9, 2008 Thanks for your suggests laffin and kenrbrsn but I already know how to do it both of those ways. $input = array ( 'home' => array( 'Home', 'something', 'something', 'index.php'), 'contact' => array( 'Contact', 'something', 'something', 'contact.php') ); if( in_array( $_GET['file'], $input ) ) { $input[$_GET['file']] } If the $_GET['page'] is home, I want to include index.php and I want to be able to access those other parts of the array ( array( 'Home', 'something', 'something', 'index.php') ), if it's contact then the same... I know there are simple workarounds to tricky ideas, but it'd be nice to know how to do this anyway.. Quote Link to comment Share on other sites More sharing options...
Barand Posted February 9, 2008 Share Posted February 9, 2008 When $_GET['page'] contains 'home', what can we expect in $_GET['file'] ? Quote Link to comment Share on other sites More sharing options...
Aureole Posted February 9, 2008 Author Share Posted February 9, 2008 I worked it out, it was simpler than I thought. <?php $page = ( isset( $_GET['page'] ) && ( $_GET['page'] ) ) ? $_GET['page'] : 'home'; $input = array ( 'home' => array( 'Home', 'website', 'public', 'index'), 'forum' => array( 'Forum Index, 'forum', 'forum', 'index'), 'contact' => array( 'Contact', 'website', 'public', 'contact') ); if( array_key_exists( $act, $input ) ) { require_once( ROOT_PATH . 'sources/' . $input[$act][2] . '/' . $input[$act][3] . '.' . $equinox->vars['php_ext'] ); $page_title = $input[$act][0]; $nav_current = $input[$act][1]; include( ROOT_PATH . 'sources/inc/header.' . $equinox->vars['php_ext'] ); echo( $page_html ); include( ROOT_PATH . 'sources/inc/footer.' . $equinox->vars['php_ext'] ); } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.