简体   繁体   中英

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. The resulting Y or N is being passed into an XML line. I'm using 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.

An alternative can be to use strlen .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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