نوع دادههای 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)
در مثالهای زیر، ما از اعداد مختلفی تست خواهیم کرد. var_dump() PHP نوع داده و مقدار متغیر را بازمیگرداند:
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
اعداد اعشاری میتوانند با نقطه یا فرمول اکسپوننسیونال باشند.
در مثالهای زیر، ما از اعداد مختلفی تست خواهیم کرد. var_dump() PHP نوع داده و مقدار متغیر را بازمیگرداند:
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 Objects
An object is a data type that stores data and information about how to handle the data.
In PHP, objects must be declared explicitly.
Firstly, 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 an 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 an empty string and a null database value.
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