Home >php教程 >php手册 >echo and print statements, echoprint statement

echo and print statements, echoprint statement

WBOY
WBOYOriginal
2016-07-06 14:25:35741browse

echo and print statements, echoprint statement

In php, there are two basic output methods: echo and print

Difference between echo and print:

  • echo - can output more than one string, no return value
  • print - can only output a string and always returns a value of 1

echo statement:

Echo is a language structure and can be used with or without parentheses: echo or echo();

For example:

Display string:

echo "

PHP is fun!

";

echo "Hello world!";

echo "Plan","Learn","PHP";

?>

Display variables:

$txt1 = "Learn PHP";

$txt2 = "***.com";

$cars = array("Volvo","BWM","AABB");

echo $txt1;

echo "
";

echo "Study PHP at $txt2";

echo "
";

echo "my car is a {$cars[0]}";

?>

Print statement:

Print is also a language structure and can be used with or without parentheses: print or print();

Display string:

print "

PHP is fun!

";

print ""Hello world!
";

print "I'm about to learn PHP!";

?>

Display variables:

$txt1="Learn PHP";

$txt2="W3School.com.cn";

$cars=array("Volvo","BMW","SAAB");

print $txt1;

print "
";

print "Study PHP at $txt2";

print "My car is a {$cars[0]}";

?> ;

Okay, that’s all for now. I’ll add more when I think of it. Netizens are welcome to comment! ! ! ! ! !

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn