PHP supports 8 data types
- scalar data types( A variable in which only one value can be stored at a time
- Boolean
- integer
- Float / Double
- String
- Compound data type (A variable in which multiple values can be stored)
- Array
- Object
- Special data types
- resource
- Null
The type of variable is not set by the programmer, rather it is decided at run type byPHP depending upon the context in which the variable is used.
Var_dump (Var_name):-
it is built in function of PHP used to getting the type of variable with content of variable
<?PHP $X= 10; var_dump($X); echo" <br>” $X= 10.65; var_dump($X); echo" <br>” $X= "PSD"; var_dump($X); echo" <br>” $X= true; var_dump($X); echo" <br>”
The output Will be :-
int(10) float(10.65) string(3)(PSD) bool True
Gettype(var_name):
It is also an Built in function in PHP it is used to get the type of variable.
<?php $a=10; $b=11.23; $c="PSD"; $d=true; echo gettype($a)."--".gettype($b)."--".gettype($c)."--".gettype($d); ?> The output will be : integer--double--string--boolean
Settype(var_name)
It is also an Built in function in PHP it is used to change the type of variable.
<?php < ?php $a=10; settype($a,"integer"); echo $a ."--".gettype($a); ?> The output will be : 10--integer
I will explain about notice error in the next class
Unset(var_name)
It is also an Built in function in PHP it is used to removing the content from variable.
<?php < ?php $a="psd"; echo gettype($a)." "; unset($a); echo gettype($a); ?> The output will be : string NULL