PHP supports various data types. Here are several primary types:
1. Strings: Used to represent textual information. Strings can be declared using either single ('single quotes') or double ("double quotes") quotes.
$str_single = 'This is a single string';
$str_double = "This is a double string";
2. Integers: Used to represent whole numbers.
$int_var = 123;
3. Floats: Used to represent numbers with a floating-point.
$float_var = 3.14;
4. Booleans: Take values of `true` or `false`.
$bool_var = true;
5. Arrays: Used to store indexed lists of values.
$array_var = array(1, 2, 3, 4, 5);
6. Objects: Used to create instances of classes.
class MyClass {
public $property = 'Property value';
}
$object_var = new MyClass();
7. Resources: Represent external resources such as file descriptors or database connections.
8. NULL: Used to indicate the absence of a value.
$null_var = null;
These are just the basic data types in PHP. In addition, PHP has some special types like resources and NULL, and it can interact with more complex data types such as regular expressions and resources.