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
trueorfalse. 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.
Your Feedback
Help us improve by sharing your thoughts
Online Learner helps developers master programming, database concepts, interview preparation, and real-world implementation through structured learning paths.
Quick Links
© 2023 - 2026 OnlineLearner.in | All Rights Reserved.
