You want to output a variable's value along with some text in PHP. How would you use echo or print to do this?

  • echo "Text" . $variable;
  • echo "Text $variable";
  • print "Text" . $variable;
  • print "Text $variable";
To output a variable's value along with some text in PHP, you can use either echo or print. One way is to concatenate the text and the variable using the dot (.) operator. For example, echo "Text" . $variable; will concatenate the string "Text" with the value of the variable. Another way is to use string interpolation by enclosing the variable within double quotes. For example, echo "Text $variable"; will automatically substitute the variable's value within the string. Both echo and print can achieve this task effectively. Learn more: https://www.php.net/manual/en/function.echo.php https://www.php.net/manual/en/function.print.php
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *