Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Feb 2005
    Posts
    663
    Thanks
    5
    Thanked 14 Times in 14 Posts

    Search Array Keys and return value

    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?

    [php]
    // 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';
    }[/code]

  • #2
    Regular Coder bacterozoid's Avatar
    Join Date
    Jun 2002
    Location
    USA
    Posts
    490
    Thanks
    24
    Thanked 35 Times in 35 Posts
    PHP Code:
    // Or how about this?
    $context['sub_template'] = $subactions[$_REQUEST['sa']];
    // where $_REQUEST['sa'] is either 'browser' or 'create' 

  • #3
    Regular Coder
    Join Date
    Feb 2005
    Posts
    663
    Thanks
    5
    Thanked 14 Times in 14 Posts
    Works perfect. Thanks !!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •