戻る

PHPのデータ型

論理値(boolean/bool)

<?php
header("Content-type: text/plain; charset=utf-8");
	
$flg = True;
	
echo gettype($flg);
?>

整数(integer/int)

<?php
header("Content-type: text/plain; charset=utf-8");
	
$num = 123;
	
echo gettype($num);
?>

10進数の「2147483647」は2進数にすると「1111111111111111111111111111111」となり、それ以上の数値はデータ型の確保できるメモリがオーバーフローし、double型に自動型変換されます。

浮動小数点(float/double)

<?php
header("Content-type: text/plain; charset=utf-8");
	
$num = 1.234;
	
echo gettype($num);
?>

「0.99999999999999」より精密な実数はオーバーフローし、自動的に1に繰り上げられます。

10進数の「99999999999999」を超える数値は対数で表示されます。

文字列(string)

<?php
header("Content-type: text/plain; charset=utf-8");
	
$num = "123";
	
echo gettype($num);
?>

配列(array)

<?php
header("Content-type: text/plain; charset=utf-8");
	
$ary = Array("あああ",123,1.23,True);
	
echo gettype($ary);
?>

オブジェクト(object)

<?php
header("Content-type: text/plain; charset=utf-8");
	
$obj = new __PHP_Incomplete_Class();

echo gettype($obj);
?>

リソース(resource)

<?php
header("Content-type: text/plain; charset=utf-8");
	
$file = fopen("c:\\xampp\htdocs\resource.php", "r");

echo gettype($file);
?>

ヌル(NULL)

<?php
header("Content-type: text/plain; charset=utf-8");
	
$var = NULL;

echo gettype($var);
?>

inserted by FC2 system