note 118929 added to function.array-diff
| From: | true===$gmail | Date: | Tue, 01 Mar 2016 09:59:17 +0000 |
| Subject: | note 118929 added to function.array-diff | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-205072@lists.php.net to get a copy of this message | ||
This function comes in handy if we want to compare two array values only
For example we want to make a quick check on some required $_POST parameters:
function required_array($required_array_values, $dynamic_array_values){
return (count(array_diff(
$required_array_values,
$dynamic_array_values
)) > 0) ? false : true;
}
// we expect $_POST['change_password'][new, old, repeat]
$required_params = required_array(
array('old','new','repeat'),
array_keys($_POST['change_password'])
);
if( !$requred_params ){
die('error: all parameters are required!');
}else{
echo 'good to go';
}
----
Server IP: 72.52.91.14
Probable Submitter: 80.90.95.34
----
Manual Page -- http://php.net/manual/en/function.array-diff.php
Edit -- https://master.php.net/note/edit/118929
Del: integrated -- https://master.php.net/note/delete/118929/integrated
Del: useless -- https://master.php.net/note/delete/118929/useless
Del: bad code -- https://master.php.net/note/delete/118929/bad+code
Del: spam -- https://master.php.net/note/delete/118929/spam
Del: non-english -- https://master.php.net/note/delete/118929/non-english
Del: in docs -- https://master.php.net/note/delete/118929/in+docs
Del: other reasons-- https://master.php.net/note/delete/118929
Reject -- https://master.php.net/note/reject/118929
Search -- https://master.php.net/manage/user-notes.php