In PHP, data types tell the computer what kind of value a variable can hold. For example, a number is stored differently than text. Understanding data types is important because it helps you use variables correctly in your program.
A string is a sequence of characters, like text. Strings are always written inside quotes.
<?php
$name = "John Doe";
echo "Hello, my name is $name";
?>
"John Doe" is a string value.Hello, my name is John Doe.An integer is a whole number without decimals.
<?php
$age = 25;
echo "I am $age years old.";
?>
25 is an integer.I am 25 years old.A float is a number with a decimal point.
<?php
$price = 49.99;
echo "The price is $price dollars.";
?>
49.99 is a float value.The price is 49.99 dollars.A boolean has only two possible values: true or false. It is often used for conditions.
<?php
$is_student = true;
if($is_student){
echo "You are a student.";
} else {
echo "You are not a student.";
}
?>
true means βyesβ or βonβ.false means βnoβ or βoffβ.You are a student.An array stores multiple values in a single variable.
<?php
$colors = array("Red", "Green", "Blue");
echo $colors[0]; // Outputs "Red"
?>
$colors[0] gives the first item (Red).NULL is a special type that means "no value" or "empty".
<?php
$value = null;
var_dump($value); // Shows NULL
?>
NULL means the variable has no value assigned.β Summary: PHP supports different data types like string, integer, float, boolean, array, and null. Choosing the right data type makes your program more reliable.