PHP Data Types
PHP supports several data types, including:
- Integer: Represents whole numbers, positive or negative, without decimals. For example:
$age = 25;
- Float (or Double): Represents numbers with decimal points. For example:
$pi = 3.14;
- String: Represents sequences of characters enclosed in single quotes (‘ ‘) or double quotes (” “). For example:
$name = "John";
- Boolean: Represents a logical value, either true or false. For example:
$isTrue = true;
- Array: Represents an ordered collection of elements, which can be of any data type. For example:
$fruits = array("apple", "banana", "orange");
- Object: Represents an instance of a class, containing properties and methods. For example:
$person = new Person();
- Null: Represents the absence of any value. For example:
$variable = null;
- Resource: Represents an external resource, such as a database connection or file handle.
- Callable: Represents a reference to a function or method that can be invoked.
- Closure: Represents an anonymous function with its own scope.
These are the core data types in PHP. Additionally, PHP also supports composite data types like associative arrays, multidimensional arrays, and objects with properties and methods.