note 77372 added to function.array-key-exists
| From: | j_hattersleydykes{at}yahoouk at osu1 dot php dot net | Date: | Mon, 27 Aug 2007 00:39:40 +0000 |
| Subject: | note 77372 added to function.array-key-exists | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-129824@lists.php.net to get a copy of this message | ||
hey - I thought this function maybe useful to someone somewhere..
It works on an array of the keys you want to check exist. you could pass in the names of form fields
and the POST array - suppose it could be useful in aiding form validation.
function array_keys_exist(array $keys, array $toCheck, $whichKey = false)
{
foreach ($keys as $array_key)
{
if (! array_key_exists($array_key, $toCheck))
{
// return first key thats not found.
if ($whichKey)
{
return $array_key;
}
else
{
return false;
}
}
}
// all keys exist
return true;
}
hope someone finds it useful :)
----
Server IP: 203.220.0.234
Probable Submitter: 123.100.64.24
----
Manual Page -- http://www.php.net/manual/en/function.array-key-exists.php
Edit -- https://master.php.net/note/edit/77372
Del: integrated -- https://master.php.net/note/delete/77372/integrated
Del: useless -- https://master.php.net/note/delete/77372/useless
Del: bad code -- https://master.php.net/note/delete/77372/bad+code
Del: spam -- https://master.php.net/note/delete/77372/spam
Del: non-english -- https://master.php.net/note/delete/77372/non-english
Del: in docs -- https://master.php.net/note/delete/77372/in+docs
Del: other reasons-- https://master.php.net/note/delete/77372
Reject -- https://master.php.net/note/reject/77372
Search -- https://master.php.net/manage/user-notes.php