Jump to content

Verify a value in an Array


unemployment

Recommended Posts

I need to verify a submitted value with one I have in an array.

 

Example...

 

<input type="hidden" name="page" id="fb_page" value="<?php echo htmlentities(substr($_SERVER['SCRIPT_NAME'], 1)); ?>" />

$pages = array(
    '1'         => 'One', 
    '2'         => 'Two',
    '3'         => 'Three', 
    '4'         => 'Four'
);

 

I need to say if the value == 'One'  then echo 1.  Keep mind that the array is in an external file.  The post is in the footer and the echoed data is in another file.  Essentially I am posting '1' to the database and then I want 'One' echoed out if it matches the value in the array.

 

Link to comment
Share on other sites

if(isset($pages[$submittedvalue])) echo $pages[$submittedvalue];

 

based upon the OP comments he needs to search the array VALUES against the user input and return the index. The above would work if you were searching the array indexes and wanted the value. array_search() is the correct solution.

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.