Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Don';如果变量为空,则不要在电子邮件中包含表-PHP_Php_Variables - Fatal编程技术网

Don';如果变量为空,则不要在电子邮件中包含表-PHP

Don';如果变量为空,则不要在电子邮件中包含表-PHP,php,variables,Php,Variables,我有html表单,并通过php处理发送电子邮件。如果变量($ans01)为空,如何隐藏表格而不包含在电子邮件中 $message .= '<table width="100%" rules="rows" style="border: 1px solid #0066cc;" cellpadding="5">'; $message .= "<tr><td colspan='2'>This line is question and answer is b

我有html表单,并通过php处理发送电子邮件。如果变量($ans01)为空,如何隐藏表格而不包含在电子邮件中

$message    .= '<table width="100%" rules="rows" style="border: 1px solid #0066cc;" cellpadding="5">';
$message    .= "<tr><td colspan='2'>This line is question and answer is below?</td></tr>";
$message    .= "<tr><td colspan='2' style='color:#0000FF;'><strong>" .$ans01. "</strong></td></tr>";
$message    .= "</table><br>";
$message.='';
$message.=“这行是问题,下面是答案?”;
$message.=“”$ans01。“”;
$message.=“
”;
只需添加if,其中的empty($ans01)等于not。代码:

if (!empty($ans01)) {
    $message    .= '<table width="100%" rules="rows" style="border: 1px solid #0066cc;" cellpadding="5">';
    $message    .= "<tr><td colspan='2'>This line is question and answer is below?</td></tr>";
    $message    .= "<tr><td colspan='2' style='color:#0000FF;'><strong>" .$ans01. "</strong></td></tr>";
    $message    .= "</table><br>";
}
if(!empty($ans01)){
$message.='';
$message.=“这行是问题,下面是答案?”;
$message.=“”$ans01.”;
$message.=“
”; }
祝你好运D

只需将if(!empty($ans01)条件添加到表的顶部即可。