Concatenating ECHO syntax in PHP

后端 未结 5 1150
南笙
南笙 2020-12-30 06:35

I have made a small function (WordPress), using echo .

/* .. Some code */
switch ($linktype) {
    case \"next\":
        echo \'

5条回答
  •  感动是毒
    2020-12-30 07:06

    everything that needs to be EVALUATED in some way (expression, function) will be inevitably "pushed" to the end when using dots?

    I can't reproduce this behavior. And, according to my knowledge, it should be contrary: echoed (not evaluated) values goes first, and then goes the result of the echo.

    it seems you are mixing 2 matters - evaluation and echoing.
    when concatenated, all expressions gets evaluated in turn:

    function aplus($b){
      global $a;
      $a += $b;
    }
    
    $a=1;
    
    echo $a."|".aplus(1).$a."||".aplus(1).$a;
    

    while if you are of bad practice of mixing echo with statements having output of their own, this separate echo goes first:

    function e($s){
      echo $s;
    }
    
    $a=1;
    
    echo $a."|".e($a +1)."||".e($a+2);
    

提交回复
热议问题