<?php
echo "Hello World";
echo "This spans
multiple lines. The newlines will be
output as well";
echo "This spans\nmultiple lines. The newlines will be\noutput as well.";
echo "Escaping characters is done \"Like this\".";
// echo 命令の中で変数を使用することが可能です
$foo = "foobar";
$bar = "barbaz";
echo "foo is $foo"; // foo is foobar
// 配列を使用することもできます
$baz = array("value" => "foo");
echo "this is {$baz['value']} !"; // this is foo !
// 値ではなく変数名を出力するシングルクオートを使用します
echo 'foo is $foo'; // foo is $foo
// 他の文字を全く使用しない場合、echo 変数を使用可能です
echo $foo; // foobar
echo $foo,$bar; // foobarbarbaz
// 複数の文字列をそれぞれ別の引数として渡しても、
// すべて連結してひとつの引数として渡してもかまいません
echo 'This ', 'string ', 'was ', 'made ', 'with multiple parameters.', chr(10);
echo 'This ' . 'string ' . 'was ' . 'made ' . 'with concatenation.' . "\n";
echo <<<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 は関数のように動作しないので、以下のコードは正しくありません
($some_var) ? echo 'true' : echo 'false';
// しかし、次の例は動作します
($some_var) ? print 'true' : print 'false'; // print も言語構造ですが、
// 関数のように動作します。なので、
// このコンテキスト中で使用できます
echo $some_var ? 'true': 'false'; // 命令を変更
?>