这里是我提供一些echo
的例子示例1
echo 'The sum is ', 1 + 2; //works fine
示例2
$x=true;
echo '$x is undefined value ' , ($x===true) ? 'NO' : 'Yes'; //Works fine
示例3
function f($arg){
return $arg;
}
echo 'hello ' , f('buddy'); //Works fine
示例4 -
echo 'hello ' , if($a) { return "wowo"; } else { return "fine"; }; // generate parse error
以下是所有示例正常工作,但示例4生成解析错误。
我的问题是 -
1. language constructs
可以用于echo
个参数吗?
2.如果可以使用是 language constructs
,我们如何将language constructs
用于echo
个参数?
3.只有返回字符串的functions
可以传递给echo
个参数吗?
答案 0 :(得分:-1)
Yes you can use language constructs to echo arguments or return values. If else is a conditional statement which can be use to evaluate a value. using this you will be able to break the the logic into several pieces and evaluate the condition. the echo will work separately for an each statement. But if you return a value , it will be returned from function and not from the statement. EX:
$value = "hello";
if($a) { $value.= "wowo"; } else { $value.= "fine"; }
echo $value;
in the other hand ternary operator is an operator that takes three arguments and performs an operation .