简体   繁体   English

PHP“如果为空”则帮助Joomla-VirtueMart

[英]PHP “if empty” help Joomla - VirtueMart

I'm having trouble with this code. 我在使用此代码时遇到麻烦。 If the field customer_note is empty, need it to return a value of N and Y if there is text in the field. 如果字段customer_note为空,则如果字段中有文本,则需要它返回NY的值。 The resulting Y or N is being passed into an XML line. 所得的YN将传递到XML行中。 I'm using PHP 5.2.9. 我正在使用PHP 5.2.9。

Thank you. 谢谢。

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

I'm not sure if you want this: 我不确定您是否要这样:

< ?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; 
?> 
$has_customer_note = empty($customer_note) ? 'N' : 'Y';

Check out the part about return values of empty to see what is considered an empty value. 查看有关empty返回值的部分,以了解什么是空值。

An alternative can be to use strlen . 另一种选择是使用strlen

$has_customer_note = strlen($customer_note) > 0 ? 'Y' : 'N';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM