dourong8495 2017-11-13 05:44
浏览 187

在PHP中传递给echo的参数

here are i am providing some examples of echo

Example 1

echo 'The sum is ', 1 + 2; //works fine

Example 2

$x=true;
echo '$x is undefined value ' , ($x===true) ? 'NO' : 'Yes'; //Works fine

Example 3

function f($arg){
  return $arg;
}

echo 'hello ' , f('buddy'); //Works fine

Example 4 -

echo 'hello ' , if($a) { return "wowo"; } else { return "fine"; }; // generate parse error

Here is the point that all example working fine but example 4 its generating parse error.

my questions is that -
1. language constructs can be used for echo arguments ?
2. If yes language constructs can be used, how can we use language constructs for echo arguments ?
3. Only functions that return strings can be passed to echo arguments ?

  • 写回答

1条回答 默认 最新

  • douti0467 2017-11-13 06:48
    关注

    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 .

    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题