What are the different types of variables in PHP?
In PHP, variables are categorized based on their data types. Here are the main types:
-
Integer: Whole numbers without a decimal point. E.g.,
$age = 25;
-
Float (or Double): Numbers with a decimal point. E.g.,
$price = 19.99;
-
String: A sequence of characters. E.g.,
$name = "John";
-
Boolean: Represents either
true
orfalse
. E.g.,$isLoggedIn = true;
-
Array: A collection of values. Can be indexed or associative. E.g.,
$colors = array("red", "green", "blue");
-
Object: An instance of a class, containing properties and methods. E.g.,
$car = new Car();
-
NULL: Represents a variable with no value. E.g.,
$var = NULL;
-
Resource: A special type used to hold references to external resources (like database connections). E.g.,
$conn = mysqli_connect("localhost", "user", "password");
These types cover most of the data you'll work with in PHP.
At Online Learner, we're on a mission to ignite a passion for learning and empower individuals to reach their full potential. Founded by a team of dedicated educators and industry experts, our platform is designed to provide accessible and engaging educational resources for learners of all ages and backgrounds.
Terms Disclaimer About Us Contact Us
Copyright 2023-2025 © All rights reserved.