I need to check if $_POST
variables exist using single statement isset.
if (isset$_POST[\'name\'] && isset$_POST[\'number\'] &&am
$variables = array('name', 'number', 'address');
foreach($variables as $variable_name){
if(isset($_POST[$variable_name])){
echo 'Variable: '.$variable_name.' is set
';
}else{
echo 'Variable: '.$variable_name.' is NOT set
';
}
}
Or, Iterate through each $_POST
key/pair
foreach($_POST as $key => $value){
if(isset($value)){
echo 'Variable: '.$key.' is set to '.$value.'
';
}else{
echo 'Variable: '.$key.' is NOT set
';
}
}
The last way is probably your easiest way - if any of your $_POST
variables change you don't need to update an array with the new names.