print 输出字符串

发表日期:2021-07-01 10:23:22 | 来源: | | 浏览(879) 分类:字符串 函数

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 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;
?>

注释

注意: 因为是一个语言构造器而不是一个函数,不能被 可变函数 调用。

参见

集速网 copyRight © 2015-2022 宁ICP备15000399号-1 宁公网安备 64010402001209号
与其临渊羡鱼,不如退而结网
欢迎转载、分享、引用、推荐、收藏。