PHP ডেটা টাইপ
- Previous Page PHP Echo / Print
- Next Page PHP স্ট্রিং ফাংশন
字符串、整数、浮点数、逻辑、数组、对象、NULL。
PHP 字符串
字符串是字符序列,比如 "Hello world!"。
字符串可以是引号内的任何文本。您可以使用单引号或双引号:
Example
<?php $x = "Hello world!"; echo $x; echo "<br>"; $x = 'Hello world!'; echo $x; ?>
PHP 整数
整数是没有小数的数字。
整数规则:
- 整数必须有至少一个数字(0-9)
- 整数不能包含逗号或空格
- 整数不能有小数点
- 整数正负均可
- 可以用三种格式规定整数:十进制、十六进制(前缀是 0x)或八进制(前缀是 0)
在下面的例子中,我们将测试不同的数字。PHP var_dump() 会返回变量的数据类型和值:
Example
<?php $x = 5985; var_dump($x); echo "<br>"; $x = -345; // 负数 var_dump($x); echo "<br>"; $x = 0x8C; // 十六进制数 var_dump($x); echo "<br>"; $x = 047; // 八进制数 var_dump($x); ?>
PHP 浮点数
浮点数是有小数点或指数形式的数字。
在下面的例子中,我们将测试不同的数字。PHP var_dump() 会返回变量的数据类型和值:
Example
<?php $x = 10.365; var_dump($x); echo "<br>"; $x = 2.4e3; var_dump($x); echo "<br>"; $x = 8E-5; var_dump($x); ?>
PHP 逻辑
逻辑是 true 或 false。
$x=true; $y=false;
逻辑常用于条件测试。您将在本教程稍后的章节学到更多有关条件测试的知识。
PHP আর্রে
Arrays store multiple values in a single variable.
In the following example, we will test different arrays. PHP var_dump() will return the data type and value of the variable:
Example
<?php $cars=array("Volvo","BMW","SAAB"); var_dump($cars); ?>
You will learn more about arrays in the later chapters of this tutorial.
PHP Object
An object is a data type that stores data and information about how to handle the data.
In PHP, you must explicitly declare an object.
First, we must declare the class of the object. For this, we use the class keyword. A class is a structure that contains properties and methods.
Then we define the data type in the object class and use this data type in the instance of the class:
Example
<?php class Car { var $color; function Car($color="green") { $this->color = $color; } function what_color() { return $this->color; } } ?>
You will learn more about objects in the later chapters of this tutorial.
PHP NULL Value
A special NULL value indicates that a variable has no value. NULL is the only possible value of the data type NULL.
NULL value indicates whether a variable is empty. It is also used to distinguish between empty strings and empty database values.
You can clear a variable by setting its value to NULL:
Example
<?php $x="Hello world!"; $x=null; var_dump($x); ?>
- Previous Page PHP Echo / Print
- Next Page PHP স্ট্রিং ফাংশন