Mga Uri ng Data ng PHP
- Previous Page PHP Echo / Print
- Next Page Mga Function ng String ng PHP
String, integer, floating-point, logic, array, object, NULL.
PHP String
Ang string ay serye ng mga character, tulad ng "Hello world!"
Ang string ay kahit anong teksto sa loob ng pahina. Maaari mong gamitin ang isang pahina o dalawang pahina:
Example
<?php $x = "Hello world!"; echo $x; echo "<br>"; $x = 'Hello world!'; echo $x; ?>
PHP Integer
Ang integer ay ang bilang na walang pampanggit na puntos
Ang alituntunin ng integer:
- Ang integer ay dapat may hindi bababa sa isang numero (0-9)
- Ang integer ay hindi dapat may kumita o espasyo
- Ang integer ay hindi dapat may pampanggit na puntos
- Maaaring maging positibo o negatibo ang integer
- Maaaring itakda ang integer sa tatlong format: decimal, hexadecimal (sa unang liwanag ay 0x) o octal (sa unang liwanag ay 0)
Sa mga sumusunod na halimbawa, amin na pagsubok ng iba't ibang bilang. Ang PHP var_dump() ay magbibigay ng uri at halaga ng variable:
Example
<?php $x = 5985; var_dump($x); echo "<br>"; $x = -345; // Negative number var_dump($x); echo "<br>"; $x = 0x8C; // Hexadecimal number var_dump($x); echo "<br>"; $x = 047; // Octal number var_dump($x); ?>
PHP Floating-point number
Ang floating-point number ay may pampanggit na puntos o anyong indeks.
Sa mga sumusunod na halimbawa, amin na pagsubok ng iba't ibang bilang. Ang PHP var_dump() ay magbibigay ng uri at halaga ng variable:
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 Logic
Ang logic ay true o false.
$x=true; $y=false;
Logic ay ginamit sa pagsusuri ng kondisyon. Makikita mo ang mas maraming kaalaman tungkol sa pagsusuri ng kondisyon sa susunod na kabanata ng tutorial na ito.
Mga Array ng 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
Objects are a data type that stores data and information about how to handle the data.
In PHP, objects must be declared explicitly.
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 then 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 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 Mga Function ng String ng PHP