哈希空间 Ctrl + F 进行搜索
首页 php手册中文版 CSS中文手册 哈希文档 Markdown在线工具

print

(PHP 4, PHP 5, PHP 7, PHP 8)

print输出字符串

说明

print(string $arg): int

输出 arg

print 实际上不是函数(而是语言结构),所以可以不用圆括号包围参数列表。

echo 最主要的区别: print 仅支持一个参数,并总是返回 1。

参数

arg

输入数据。

返回值

总是返回 1

范例

示例 #1 print 范例

<?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\".";

// 可以在打印语句中使用变量
$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;          // 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;
?>

注释

注意: 因为是语言构造器而不是函数,不能被 可变函数 或者 命名参数 调用。

参见

打开 哈希空间 微信小程序中查看更佳