簡體   English   中英

PHP“如果為空”則幫助Joomla-VirtueMart

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

我在使用此代碼時遇到麻煩。 如果字段customer_note為空,則如果字段中有文本,則需要它返回NY的值。 所得的YN將傳遞到XML行中。 我正在使用PHP 5.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; 
?> 
$has_customer_note = empty($customer_note) ? 'N' : 'Y';

查看有關empty返回值的部分,以了解什么是空值。

另一種選擇是使用strlen

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM