Php/docs/function.print
(PHP 4, PHP 5, PHP 7)
print — 输出字符串
说明
print
( string $arg
) : int
输出 arg
。
print 实际上不是函数(而是语言结构),所以可以不用圆括号包围参数列表。
和 echo
最主要的区别:
print
仅支持一个参数,并总是返回 1。
参数
arg
- 输入数据。
返回值
总是返回 1
。
范例
Example #1 print 范例
<?phpprint("Hello World");print "print() also works without parentheses.";print "This spansmultiple lines. The newlines will beoutput as well";print "This spans\nmultiple lines. The newlines will be\noutput as well.";print "escaping characters is done \"Like this\".";// 可以在打印语句中使用变量$foo = "foobar";$bar = "barbaz";print "foo is $foo"; // foo is foobar// 也可以使用数组$bar = array("value" => "foo");print "this is {$bar['value']} !"; // this is foo !// 使用单引号将打印变量名,而不是变量的值print 'foo is $foo'; // foo is $foo// 如果没有使用任何其他字符,可以仅打印变量print $foo; // foobarprint <<<ENDThis uses the "here document" syntax to outputmultiple lines with $variable interpolation. Notethat the here document terminator must appear on aline with just a semicolon no extra whitespace!END;?>
注释
Note:
因为是一个语言构造器而不是一个函数,不能被可变函数 调用。