类似于php echo
语句,php print
是一个语言结构(因为有返回值,可以认为它是函数),所以也不需要使用括号和参数列表。 与echo
不同,它总是返回1
。
php print
的语法如下:
int print(string $arg)
php print语句可以用来打印字符串,多行字符串,转义字符,变量,数组等。
file: print1.php
<?php
print "hello by php print ";
print ("hello by php print()");
?>
执行上面代码得到以下结果 -
hello by php print hello by php print()
file: print2.php
<?php
print "hello by php print
this is multi line
text printed by
php print statement
";
?>
执行上面代码得到以下结果 -
hello by php print this is multi line text printed by php print statement
file: print3.php
<?php
print "hello escape \"sequence\" characters by php print";
?>
执行上面代码得到以下结果 -
hello escape "sequence" characters by php print
file: print4.php
<?php
$msg="hello print() in php";
print "message is: $msg";
?>
执行上面代码得到以下结果 -
message is: hello print() in php