PHP Data Types
PHP Data Types-
PHP Data Types, Variables can store data of different types, PHP supports 8 primitive data types that can be categorized further into 3 types:

- Scalar Types
- Compound Types
- Special Types
PHP Data Types: Scalar Types
There are 4 scalar data types in PHP.
- string
- float
- integer
- boolean
PHP Data Types: Compound Types
There are 2 compound data types in PHP.
- object
- array
Special Types
There are 2 special data types in PHP.
- resource
- NULL
PHP String
a string is a sequence of characters, like “Wellcome Tutorial Scan” and can be used singly or double quotes
Example:-
|
1 2 3 4 5 6 7 |
<?php $x = "Welcome Tutorial Scan!"; $y = 'Welcome Tutorial Scan!'; echo $x; echo "<br>"; echo $y; ?> |
Output:
|
1 2 |
Welcome Tutorial Scan! Welcome Tutorial Scan! |
PHP Integer
- PHP integer must have at least one digit
- The integer must not have a decimal point
- it integer can be either positive or negative
- Integers can be specified in three formats: decimal (10-based), hexadecimal (16-based – prefixed with 0x) or octal (8-based – prefixed with 0)
Example:-
|
1 2 3 4 |
<?php $x = 3456; var_dump($x); ?> |
Output:-
|
1 |
int(3456) |
PHP Float
A float is a number with a decimal point or a number in exponential form.
$x is a float. The PHP var_dump() function returns the data type and value:
Example:-
|
1 2 3 4 |
<?php $x = 23.542; var_dump($x); ?> |
Output:-
|
1 |
float(23.542) |
PHP Boolean-
A Boolean represents always two possible conditions: TRUE or FALSE.
|
1 2 |
$x = true; $y = false; |
PHP Array
An array stores multiple values in one single variable.
In the following example, $watch is an array. The PHP var_dump() function returns the data type and value:
Example:-
|
1 2 3 4 |
<?php $watch = array("HMT","Reebok","Titen"); var_dump($watch); ?> |
Output:-
|
1 |
array(3) { [0]=> string(3) "HMT" [1]=> string(6) "Reebok" [2]=> string(5) "Titen" } |
Resource
PHP.net