如何在关联数组中获取空值的键


how to get key of null value in associative array in php

我在php中做html表单的验证,我想打印出一个空字段的键,

$url = $_POST['url']; $start_time = $_POST['start_time']; $end_time = $_POST['end_time'];
$arr = array("Url"=>"$url","Start Time"=>"$start_time","End Time"=> "$end_time");

代替....

$url = $_POST['url']; $start_time = $_POST['start_time']; 
$end_time = $_POST['end_time'];

我建议

$err =0;
 // repeat following block for every mandatory input
if ((isset($_POST['url']) && (!empty($_POST['url']))){
$url = $_POST['url'];
} else {$err++;  $errmsg .='You need to enter a URL<br>';}

if ($err > 0){
echo $errmsg;
} else {
// process submitted form 
}

例如,我更喜欢在对用户提供的变量执行任何操作之前先查找错误。