(PHP 4, PHP 5, PHP 7)
print — 文字列を出力する
説明
print
( string $arg
) : int
arg
を出力します。
print
は実際には関数ではありません
(言語構造です)。このため、引数を括弧で括る必要はありません。
echo
との主な違いは、
print
が単一の引数のみ受け付け、常に 1 を返すことです。
パラメータ
arg
- 入力データ。
返り値
常に 1
を返します。
例
例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\".";// print文の中で変数を使用することが可能です。$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;?>
注意
注意:
これは、関数ではなく言語構造のため、可変関数 を用いて コールすることはできません。