Home  >  Article  >  Backend Development  >  echo, print, printf 和 sprintf 区别_php技巧

echo, print, printf 和 sprintf 区别_php技巧

WBOY
WBOYOriginal
2016-05-17 09:43:05960browse

- echo 

是命令,不能返回值。echo后面可以跟很多个参数,之间用分号隔开,如: 
echo $myvar1; 
echo 1,2,$myvar,"bold"; 

- print 

是函数,可以返回一个值,只能有一个参数。 

- printf 

函数,把文字格式化以后输出,如: 
$name="hunte"; 
$age=25; 
printf("my name is %s, age %d", $name, $age); 

- sprintf 

跟printf相似,但不打印,而是返回格式化后的文字,其他的与printf一样。 
- echo 

是命令,不能返回值。echo后面可以跟很多个参数,之间用分号隔开,如: 
echo $myvar1; 
echo 1,2,$myvar,"bold"; 

- print 

是函数,可以返回一个值,只能有一个参数。 

- printf 

函数,把文字格式化以后输出,如: 
$name="hunte"; 
$age=25; 
printf("my name is %s, age %d", $name, $age); 

- sprintf 

跟printf相似,但不打印,而是返回格式化后的文字,其他的与printf一样。

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