note 95664 added to function.array-key-exists
| From: | gmdebby at gmail dot com | Date: | Thu, 14 Jan 2010 13:44:49 +0000 |
| Subject: | note 95664 added to function.array-key-exists | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-164970@lists.php.net to get a copy of this message | ||
A little function which take an array as keys
<?php
//note the s in the function name (keys)
function array_keys_exists($array,$keys) {
foreach($keys as $k) {
if(!isset($array[$k])) {
return false;
}
}
return true;
}
?>
//useful to validate a form for example
<form>
<input type="text" name="field1" /><br />
<input type="text" name="field2" /><br />
<input type="text" name="field3" /><br />
<input type="text" name="field4" /><br />
<input type="text" name="field5" /><br />
</form>
<?php
if(!array_keys_exists($_POST,
array("field1","field2","field3","field4","field5")
)) {
//some fields are missing, dont do anything (maybe hacking)
} else {
//code ...
}
?>
----
Server IP: 195.221.21.36
Probable Submitter: 93.16.82.62
----
Manual Page -- http://www.php.net/manual/en/function.array-key-exists.php
Edit -- https://master.php.net/note/edit/95664
Del: integrated -- https://master.php.net/note/delete/95664/integrated
Del: useless -- https://master.php.net/note/delete/95664/useless
Del: bad code -- https://master.php.net/note/delete/95664/bad+code
Del: spam -- https://master.php.net/note/delete/95664/spam
Del: non-english -- https://master.php.net/note/delete/95664/non-english
Del: in docs -- https://master.php.net/note/delete/95664/in+docs
Del: other reasons-- https://master.php.net/note/delete/95664
Reject -- https://master.php.net/note/reject/95664
Search -- https://master.php.net/manage/user-notes.php