Hello friends, in this tutorial, we will learn about data types in php and it supports 8 different data types, which are classified into 3 main types.
Four scalar types:
- boolean
- integer
- float
- string
Four compound types:
- array
- object
- callable
- iterable
And finally two special types:
- resource
- NULL
The type of variable is not usually set by the programmer; Instead, it is determined by PHP based on the runtime in which that variable is used.
Example:
<?php
$var_bool = TRUE; // a boolean
$var_str = "foo"; // a string
$var_str2 = 'foo'; // a string
$var_int = 12; // an integer
$var_float = 12.12; // a float
$var_null = null; // a null
$var_array = array ("php", "java", "android", "ios"); // a array
echo gettype($var_bool); // prints out: boolean
echo gettype($var_str); // prints out: string
?>
Note:- Resources PHP does not have a specific data type. By default, this is used to store some function calls or references to external PHP resources
I hope this tutorial help for you.
Related Post