1:echo:是语句不是函数,没有返回值,可输出多个变量值,不需要圆括号。不能输出数组和对象,只能打印简单类型(如int,string)。
2:print:是语句不是函数,有返回值 1 ,只能输出一个变量,不需要圆括号。不能输出数组和对象,只能打印简单类型(如int,string)。
输出字符串
echo "<h2>PHP is fun!</h2>";
echo "Hello world!<br>";
echo "I'm about to learn PHP!<br>";
echo "This", " string", " was", " made", " with multiple parameters.";
print "<h2>PHP is fun!</h2>";
print "Hello world!<br>";
print "I'm about to learn PHP!";
输出变量
echo "Study PHP at $txt2"; //php 双引号内部可包含变量
echo "My car is a {$cars[0]}"; //用大括号 显式的指定这是变量
print "Study PHP at $txt2";
print "My car is a {$cars[0]}";