#2 - PHP Data Types
There are eight fundamental data types in PHP. Here’s an overview of these eight types.
Data Types | Description | Example |
---|---|---|
String | A sequence of characters inside quotes | “Hello World” |
Boolean | A boolean represent two states: true/false | true false |
NULL | Shows absence of a value. An unassigned variable has the value null | $a; // variable a is null |
Array | An array stores multiple values in a single variable | [1,2,3,4,5,6,7,8,9,10] |
Integer | An integer represents a non-decimal number | 100 -2 2000 1 |
Double | A double represents decimal or numbers in exponential form | 3.14159 22.6 -3.1 |
Object | An instance of a class that inherits its attributes and methods | $person = new Person() |
Resource | A resource data type is a reference to an external resource like a file or database | Database call |
xxxxxxxxxx
21
<?php
//Output: string
echo gettype("Hello World");
//Output: boolean
echo(gettype(true));
//Output: array
echo gettype(["Welcome","To","AlgoDaily"]);
//Output: integer
echo gettype(100);
//Output: double
echo gettype(3.14149);
//Output: NULL
echo gettype(null);
?>
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment