PHP supports eight primitive types.
Four scalar types:
1). Boolean
2). Integer
3). Float (floating-point number, aka 'Double')
4). String
Two compound types:
1). Array
2). Object
And finally two special types:
1). Resource
2). NULL
This is the easiest type. A boolean expresses a truth value. It can be either TRUE or FALSE.
Syntax:-
To specify a boolean literal, use either the keyword TRUE or FALSE. Both are case insensitive.
An integer is a number of the set Z = {..., -2, -1, 0, 1, 2, ...}.
Syntax:-
Integers can be specified in decimal (10-based), hexadecimal (16-based) or octal (8-based) notation, optionally preceded by a sign (- or +).
If you use the octal notation, you must precede the number with a 0 (zero), to use hexadecimal notation precede the number with 0x.
Floating point numbers (AKA "floats", "doubles" or "real numbers") can be specified using any of the following
Syntax:-
String values are sequence of characters, included in a single quote or double quotes,
PHP Example:-‘This is a string’.
The value inside the quotes are not modified, so if you want to use quotes inside the string, then they have to be escaped, we escape characters in PHP by using backslash,
PHP Example:- ‘She wrote: \’PHP is easy to learn\’’.
\n line feed
\r Carriage return
\t Tab
\\ Backslash
\” Double quotes
PHP Example:-
“This is \n a string”, this will evaluate to:
This is
a string
An array is a collection of elements of heterogeneous type.
Go TopMore...An object is a collection of data and code. To initialize an object, you use the new statement to instantiate the object to a variable.
Syntax:-
A resource is a special variable, holding a reference to an external resource. Resources are created and used by special functions.
Go TopThe special NULL value represents that a variable has no value. NULL is the only possible value of type NULL. A variable is considered to be NULL if
it has been assigned the constant NULL.
it has not been set to any value yet.
it has been unset().
Syntax:-
That is the case insensitive keyword NULL.