(PHP 4, PHP 5, PHP 7)
print - 输出一个字符串
描述
int print ( string $arg )
输出 arg
.
print 实际上并不是一个真正的函数(它是一种语言结构),因此您不需要在其参数列表中使用括号。
与echo
的主要区别在于print
仅接受一个参数,并且始终返回1。
参数
arg
输入数据。
返回值
总是返回1
。
例子
示例#1
打印
示例
<?php
print("Hello World"
print "print() also works without parentheses.";
print "This spans
multiple lines. The newlines will be
output as well";
print "This spans\nmultiple lines. The newlines will be\noutput as well.";
print "escaping characters is done \"Like this\".";
// You can use variables inside a print statement
$foo = "foobar";
$bar = "barbaz";
print "foo is $foo"; // foo is foobar
// You can also use arrays
$bar = array("value" => "foo"
print "this is {$bar['value']} !"; // this is foo !
// Using single quotes will print the variable name, not the value
print 'foo is $foo'; // foo is $foo
// If you are not using any other characters, you can just print variables
print $foo; // foobar
print <<<END
This uses the "here document" syntax to output
multiple lines with $variable interpolation. Note
that the here document terminator must appear on a
line with just a semicolon no extra whitespace!
END;
?>
注意
注意
:因为这是一种语言结构而不是函数,所以不能使用变量函数来调用它。
扩展内容
- echo - 输出一个或多个字符串
- printf() - 输出格式化的字符串
- flush() - 刷新系统输出缓冲区
- Heredoc语法
← parse_str
printf →