PHP echo 和 print 语句
echo 和 print 区别:
echo - 可以输出一个或多个字符串
print - 只允许输出一个字符串,返回值总为 1
提示:echo 输出的速度比 print 快, echo 没有返回值,print有返回值1。
echo输出代码:
显示字符串:
echo "
PHP is fun!
";
echo
"Hello world!"
;
echo
"I'm about to learn PHP!"
;
echo
"This"
,
" string"
,
" was"
,
" made"
,
" with multiple parameters."
;
显示变量:
$txt1=
"Learn PHP"
;
$txt2=
"w3cschool.cc"
;
$cars=array(
"Volvo"
,
"BMW"
,
"Toyota"
);
echo $txt1;
echo
""
;
echo
"Study PHP at $txt2"
;
echo
"My car is a {$cars[0]}"
;
print 命令
输出字符串(字符串可以包含 HTML 标签):
print "
PHP is fun!
";
print
"Hello world!"
;
print
"I'm about to learn PHP!"
;
显示变量:
$txt1=
"Learn PHP"
;
$txt2=
"w3cschool.cc"
;
$cars=array(
"Volvo"
,
"BMW"
,
"Toyota"
);
print $txt1;
print
""
;
print
"Study PHP at $txt2"
;
print
"My car is a {$cars[0]}"
;