Page 1 of 1

Search for all Array values in another Array

Posted: Sun Apr 10, 2005 7:41 am
by anjanesh
I want to make sure $_POST['a'], $_POST['b'] and $_POST['c'] exist.
I need a function to return 3. I thought this would but doesnt :

Code: Select all

echo array_search(array('a','b','c'),array_keys($_POST));
in_array(array('a','b','c'),array_keys($_POST)) is always returning false even when $_POST['a'], $_POST['b'] and $_POST['c'] exist.
Any other way ?
Thanks

Posted: Sun Apr 10, 2005 8:22 am
by Chris Corbyn
There'll be a better way but here's my take on it :-D

Code: Select all

$reqd = array('a', 'b', 'c');
$check = 0;
foreach ($reqd as $v) {
    if (array_key_exists($v, $_POST)) {
        $check++;
    }
}
if ($check == count($reqd)) {
    //All OK
}