Write a program to print two variables in single echo
Description: Write a PHP program to print two variables using only one echo statement.
Rules and hints:
- The first variable has the text “Good Morning.”
- The second variable has the text “Have a nice day!”
- The output must be: Good Morning. Have a nice day!
- You can use only one echo statement.
PHP program to print two variables in a single echo
<?php
$first = "Good Morning.";
$second = "Have a nice day!";
echo $first . " " . $second;
?>
Output:
Tutorials Class - Output Window
Good Morning. Have a nice day!
How it works
- The dot operator joins the two variables, and a space in quotes is added between them.
- Another way is the comma:
echo $first, " ", $second;.
See three ways to print many variables in one echo.
Learn more about the similar topics:
| Tutorials |
|---|
| PHP Variables |