Home >Backend Development >PHP Tutorial >The difference between echo, print, printf and sprintf_PHP Tutorial

The difference between echo, print, printf and sprintf_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 15:59:41794browse

- echo

is a command and cannot return a value. Echo can be followed by many parameters, separated by semicolons, such as:
echo $myvar1;
echo 1,2,$myvar,"bold";

- print

is a function that can return a value and can only have one parameter.

- printf

function, format the text and then output it, such as:
$name="hunte";
$age=25;
printf("my name is %s, age %d", $name, $age);

- sprintf

is similar to printf, but does not print, but returns formatted text, others Same as printf.
- echo

is a command and cannot return a value. Echo can be followed by many parameters, separated by semicolons, such as:
echo $myvar1;
echo 1,2,$myvar,"bold";

- print

is a function that can return a value and can only have one parameter.

- printf

function, format the text and then output it, such as:
$name="hunte";
$age=25;
printf("my name is %s, age %d", $name, $age);

- sprintf

is similar to printf, but does not print, but returns formatted text, others Same as printf.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/317297.htmlTechArticle-echo is a command and cannot return a value. Echo can be followed by many parameters, separated by semicolons, such as: echo$myvar1; echo1,2,$myvar,"bold"; -print is a function that can return a value,...
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