0

I remember that there were function that have such functionality. Unfortunately, I don't remember the name of it. Basically, it did something like...

$values = foo(array('x', 'y', 'z'), $_POST);

If there are such keys in the array, it does return new array (named $values) with only those keys... taken from $_POST. If one or more keys aren't in $_POST, it simply returns false.

Anyone remember something like that or I was just dreaming? Thanks in advice!

2

3 Answers 3

2

http://www.php.net/manual/en/function.array-intersect-key.php

Sign up to request clarification or add additional context in comments.

Comments

0

I think the function you are looking for is array_intersect_key() As of PHP 5.1.0.

array array_intersect_key ( array $array1 , array $array2 [, array $ ... ] )

Parameters

array1 - The array with master keys to check.

array2 - An array to compare keys against.

array - A variable list of arrays to compare.

Returns an associative array containing all the entries of array1 which have keys that are present in all arguments.

Comments

0

check out this function array_key_exists

<?php

   $search_array = array('first' => 1, 'second' => 4);
   if (array_key_exists('first', $search_array)) 
   {
     echo "The 'first' element is in the array";
   }
?>

http://www.php.net/manual/en/function.array-key-exists.php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.