Could someone please let me know if they think it would be possible to utilize the array_search() function on $HTTP_POST_VARS..for example

upon printing the $HTTP_POST_VARS, I receive this on the screen:

Array ( [50] => 30 [51] => 0 [Submit] => 1 )

I'd then simple like to set the value of a specific key value and thought that I could simply do something like this:

$var1=array_search($qid,$HTTP_POST_VARS);

where $qid is equal to the key value.

any suggestions?

oh. wait a second...array_search() pulls the array key and not the associated array value.

Perhaps, I should restate my question then.

Does anyone know which array function I should use to set a variable to array value based upon a array key?

    Well, for starters, $HTTP*VARS have been deprecated for a while now. You should be using the $POST, $GET, $_SESSION, etc., super-global arrays. Since they're arrays, yes you can use array_search() or any array function on them.

    To get the value of a specific array element into a variable, just use:

    $var1 = $_POST[$qid];

    You could also easily check to see if there is a value in there under that key by using [man]isset/man:

    if(isset($_POST[$qid]))
        $var1 = $_POST[$qid];
    else
        $var1 = false;

      No, but I made this one for you.

      <?php
      function value2key(array $first, $key){
        if(isset($first[$key]))
          return $first[$key];
        else
          return false;
      }
      ?>
        Write a Reply...