Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.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
PHP“if empty”帮助Joomla-VirtueMart_Php - Fatal编程技术网

PHP“if empty”帮助Joomla-VirtueMart

PHP“if empty”帮助Joomla-VirtueMart,php,Php,我的代码有问题。如果字段customer_note为空,如果字段中有文本,则需要它返回一个值N和Y。结果Y或N被传递到XML行中。我使用的是PHP5.2.9 多谢各位 if( !empty( $customer_note )) { $shopper_message .= $customer_note."\n"; } else { $shopper_message .= "\n"; } 我不确定你是否想要这个: < ?php function check_ifempty($cus

我的代码有问题。如果字段customer_note为空,如果字段中有文本,则需要它返回一个值N和Y。结果Y或N被传递到XML行中。我使用的是PHP5.2.9

多谢各位

if( !empty( $customer_note )) {
  $shopper_message .= $customer_note."\n";
} else {
  $shopper_message .= "\n";
}

我不确定你是否想要这个:

< ?php 
function check_ifempty($customer_note)
    {
        if (empty($customer_note)) 
        { 
  return "N"; 
 } 
 else 
 { 
  return "Y"; 
 } 
} 
?>

< ?php 
$customer_note = $_POST["customer_note"]; 
$result = check_ifempty($customer_note); 
$xml .= $result; 
?> 
请查看有关的返回值的部分,以查看什么被视为空值

另一种选择是使用


将值返回到何处?您显示的代码似乎很不完整Y或N是什么?代码是否与您的问题有关?你的具体问题是什么?
$has_customer_note = empty($customer_note) ? 'N' : 'Y';
$has_customer_note = strlen($customer_note) > 0 ? 'Y' : 'N';