In PHP, variables can hold different types of data. PHP automatically converts the variable to the correct data type based on its value.
Main data types in PHP:
<?php $string = "Hello World"; // String $int = 100; // Integer $float = 99.99; // Float $bool = true; // Boolean $array = array("HTML", "CSS", "PHP"); // Array $null = NULL; // NULL ?>
Text enclosed in quotes:
$text = "Technorank is awesome!";
Whole numbers without decimal:
$age = 21;
Numbers with decimals:
$temperature = 36.6;
Returns either true
or false
:
$is_active = true;
Stores multiple values:
$colors = array("Red", "Green", "Blue"); echo $colors[0]; // Output: Red
Used in Object-Oriented Programming (OOP):
class Car { public $brand = "Honda"; } $myCar = new Car(); echo $myCar->brand;
A variable with no value assigned:
$x = NULL;
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!