➤ PHP
echo
statement can be used to print the string,
multi-line strings, escaping characters, variable, array, etc.
• printing string
echo "Hello friends!\n";
• printing multi line string
echo "How are you ?
this is multi line
text !\n";
• printing escaping characters
echo "Hello \"Hello\" Hello\n";
• printing variable value ( only DOUBLE quetes can parse variables )
$num= 17;
echo "num = $num\n";
// or => echo "num = ".$num."\n";
// or => echo 'num = '.$num."\n";
• printing number without quotes
echo 10;
• printing multiple parameters
echo "red"," yellow"," black";
• echo can be used with or without parentheses: echo(), and echo.
echo ("function\n");
• Text inside double quotes can include single quotes as part of the text.
The opposite is also possible.
echo "My name is 'Anton'\n";
echo 'My name is "Anton"';
➤ PHP
print
statement works exactly the same way except
that the print statement can only output one parameter, and always returns 1.
• returns 1
$result = print"Hello\n";
echo "result = $result"; // output: 1
•
print
can take only one argument
print "hello","world"; // error