php check if two variables are empty and merge them togheter

Wednesday, November 4, 2015

First thing first, i'm new to php.



I'm trying to check if two variables are both empty, and if so merge them togheter to display only one result, but if one of them is not empty, than i have to display is value.



Here's the code i tried so far:



function displayCustomerOrderNotes($customerNotesWC,$DYSPrintableOrderNotes){
if ($customerNotesWC == "") {
$customerNotesWC = "(none)";
}
if ($DYSPrintableOrderNotes ==""){
$DYSPrintableOrderNotes = "(none)";
}
if ($DYSPrintableOrderNotes == "(none)" && $customerNotesWC == "(none)"){
$NotesToDisplay = "(none)";
}
else {
$NotesToDisplay = $customerNotesWC . "<br/>" . $DYSPrintableOrderNotes;
}
}


Unfortunately this doesn't work, as the results is the following:



(none)    
Pre-sale order note


I know that there must be a better way to achieve this, and any suggestions will be really appreciated.
Thanks a lot

0 comments:

Post a Comment