我知道我可以通过使用来检查超全局$ _POST是否为空
empty / isset
Run Code Online (Sandbox Code Playgroud)
但是,我这里有很多领域.是否有任何快捷方式可以检查是否所有字段都已填满?而不是做
if (!empty($_POST['a']) || !empty($_POST['b']) || !empty($_POST['c']) || !empty($_POST['d']).... ad nauseum)
Run Code Online (Sandbox Code Playgroud)
提前致谢!
您可以使用array_filter并比较两个计数
if(count(array_filter($_POST))!=count($_POST)){
echo "Something is empty";
}
Run Code Online (Sandbox Code Playgroud)
您可以遍历$ _POST变量。
例如:
$messages=array();
foreach($_POST as $key => $value){
if(empty($value))
$messages[] = "Hey you forgot to fill this field: $key";
}
print_r($messages);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1909 次 |
| 最近记录: |