echo takes a string literal as its only argument. You can't execute logic as part of the string, you have to join the whatever the logic produces as a new string using the . (period) join string operator. While you can put logical statements in parentheses joined by the period operator, and put the whole resulting string into an echo, in your case and in most cases it makes a lot more sense to start with a string, build on it as necessary, and then echo it when it's done. e.g.
PHP Code:$output = 'hello ';
if ($a==0) {
$output .= 'world';
} else {
$output .= 'people';
}
echo $output;




Reply With Quote