View Full Version : Search Array Keys and return value

03-16-2010, 01:06 AM
Its been a while since I've look at php, and every thing I know is self taught...

I'm trying to search an array comparing its key and, than to return the value when a match is found. I think I'm on the right track, but can't seem to get it quite right. Can any give a few pointers?

// List of sub actions.
$subactions = array(
'browser' => 'MainBrowser',
'create' => 'CreateGame'

// What are we doing?
if (isset($_REQUEST['sa']) && array_key_exists($_REQUEST['sa'], $subactions))
//$context['sub_template'] = $subactions[1]; //Should this work?
$context['sub_template'] = 'CreateGame';

03-16-2010, 01:43 AM
// Or how about this?
$context['sub_template'] = $subactions[$_REQUEST['sa']];
// where $_REQUEST['sa'] is either 'browser' or 'create'

03-16-2010, 02:01 AM
Works perfect. Thanks !! :)