What are the Basic Data Types in PHP ?
Last Updated :
09 Feb, 2024
In PHP, Basic Data Types include integers for whole numbers, floats for decimal values, strings for textual data, booleans representing true or false, arrays for storing multiple values, objects for user-defined data structures, and null for indicating the absence of a value. Understanding these data types is essential for effective data handling and manipulation in PHP scripts
Integer
PHP Integer represents whole numbers without decimal points.
Example:
$num = 10;
Float (Floating Point Number or Double)
Represents numbers with a fractional component.
$floatnum = 3.14;
String
Represents sequences of characters, enclosed within single (”) or double (“”) quotes.
$name = "John Doe";
Boolean
Represents a logical value, either true or false.
$is_active = true;
Array
Represents a collection of elements, each identified by a key.
$fruits = array("apple", "banana", "orange");
Object
Represents instances of user-defined classes, encapsulating data and functionality.
Example:
$objectVariable = new stdClass();
Null
Represents a variable with no value assigned.
$variable = null;
Share your thoughts in the comments
Please Login to comment...