echo 和 print
echo<?php
$txt1="Learn PHP";
$txt2="redd.mx.nf";
$cars=array("Volvo","BMW","SAAB");
echo $txt1;
echo "<br>";
echo "Study PHP at $txt2";
echo "My car is a {$cars}";
<?php
$txt1="Learn PHP";
$txt2="redd.mx.nf";
$cars=array("Volvo","BMW","SAAB");
print $txt1;
print "<br>";
print "Study PHP at $txt2";
print "My car is a {$cars}";
?>
echo - 能够输出一个以上的字符串
print - 只能输出一个字符串,并始终返回 1
echo 可以這樣,但 print 不行:
echo "This", " string", " was", " made", " with multiple parameters.";
提示:echo 比 print 稍快,因为它不返回任何值。 $num = 13.9;
printf("數值為:%s", $num);
printf("數值為:%.2f", $num);printf 可以設定更複雜的格式。
The differences are small: echo has no return value while print has a return value of 1 so it can be used in expressions. echo can take multiple parameters (although such usage is rare) while print can take one argument. echo is marginally faster than print.
頁:
[1]