PHPの基本的な型
基本的な型をまとめる。
// Boolean
$i = True;
$i = False;
// 整数
$a = 1234; // 10進整数
$a = -123; // 負の数
$a = 0123; // 8進数 (10進数の83と等価)
$a = 0x1A; // 16進数 (10進数の26と等価)
$a = 0b11111111; // 2進数 (10進数の255と等価
$a = -123; // 負の数
$a = 0123; // 8進数 (10進数の83と等価)
$a = 0x1A; // 16進数 (10進数の26と等価)
$a = 0b11111111; // 2進数 (10進数の255と等価
// 浮動小数点数
$a = 1.234;
$b = 1.2e3;
$c = 7E-10;
$b = 1.2e3;
$c = 7E-10;
// 文字列
echo 'this is a simple string'; //Single Quote
echo "this is a simple string"; //Double Quote
// ヒアドキュメント
$bar = <<<EOT
bar
EOT;
bar
EOT;
// 配列
$array1 = array("a", "b", "c");
$array2 = array(
"appale" => "りんご",
"orange" => "みかん",
"grapes" => "ぶどう"
);
// オブジェクト
class foo
{
function do_foo()
{
echo "foo を実行します。";
}
}
$bar = new foo;
$bar->do_foo();
{
function do_foo()
{
echo "foo を実行します。";
}
}
$bar = new foo;
$bar->do_foo();
// NULL
$i = NULL;