A data type defines the type of value a variable can hold. PHP is a loosely typed language, meaning variables do not require explicit data type declarations. PHP automatically determines the type based on the assigned value.
PHP Supports 8 Data Types
1- String (Text)
A string is a sequence of characters enclosed in double ("") or single ('') quotes.
<?php
$text = "Hello, PHP!";
echo $text;
?>
✔ Outputs: Hello, PHP!
2- Integer (Whole Numbers)
An integer is a whole number without decimals.
<?php
$number = 100;
echo $number;
?>
✔ Outputs: 100
3- Float (Decimal Numbers)
A float (or double) is a number with decimal points.
<?php
$price = 99.99;
echo $price;
?>
✔ Outputs: 99.99
4- Boolean (True/False)
A boolean represents true (1
) or false (0
).