how to check multiple $_POST variable for existence using isset()?

Use simple way with array_diff and array_keys

$check_array = array('key1', 'key2', 'key3');
if (!array_diff($check_array, array_keys($_POST)))
    echo 'all exists';

$variables = array('name', 'number', 'address');

foreach($variables as $variable_name){

   if(isset($_POST[$variable_name])){
      echo 'Variable: '.$variable_name.' is set<br/>';
   }else{
      echo 'Variable: '.$variable_name.' is NOT set<br/>';
   }

}

Or, Iterate through each $_POST key/pair

foreach($_POST as $key => $value){

   if(isset($value)){
      echo 'Variable: '.$key.' is set to '.$value.'<br/>';
   }else{
      echo 'Variable: '.$key.' is NOT set<br/>';
   }

}

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.


Do you need the condition to be met if any of them are set or all?

foreach ($_POST as $var){
    if (isset($var)) {

    }
}