Jump to content

[SOLVED] Array help...


Aureole

Recommended Posts

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?

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

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'] );
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.