在一个PHP文件中,$_REQUEST []或$_POST []接收到许多变量,如果函数isset()的值为空,我必须检查它们,这很麻烦.有更好的解决方案吗?
解决方法:
// array of possible parameters that can be passed by the client
$keys = array('username','password');
// this will store the names of the ones that are not present
$missing = array();
foreach($keys as $key) {
if(!in_array($key, $_POST)) {
$missing[] = $key;
}
}
$nullOffsets = array_map("is_null", $_POST);
echo 'Printing missing params:<br />';
print_r($missing);
echo 'Printing null existing params:<br />';
print_r($nullOffsets);