When a variable is assigned, PHP automatically sets a data type. The following data types are possible:
Data type |
Purpose |
Example (PHP code) |
|---|---|---|
Int |
Number |
$number = 1; |
Float/Double |
Decimal number (123.00) |
$decimal = 1.345; |
String |
Text |
$text = "Hello World!"; |
Boolean |
True/False |
$true = true; $false = false; |
Array |
Several values, tables |
$values = array(1,2,3,4); $table = array("peter" => 5, "paul" => 2); |
Object |
Classes |
$exception = new Exception("Test"); |
Ressource |
Files, Databases |
$file = fopen("file.txt", "r"); |