You don't need to store echo
in the variable. When you want to use the variable later, that is when you call echo. Your code should look like:
$test = (!empty($row['A'])) ? 'sale' : '';
This is a ternary operator which is basically a shorthand for the following if/else:
if(!empty($row['A'])) {
$test = 'sale';
} else {
$test = '';
}
In this case, I set it to an empty string if $row[a]
is empty so nothing bad happens if you echo it later. (You want to make sure your variable is defined no matter what, so you don't cause an error by trying to call an undefined variable.)
Then, to use it, simply call
echo $test;
Why do you want to put the function inside of an echo? That defeats the point of storing a variable in the first place.