Data Types in PHP

Getting Started with PHP
Getting Started with PHP : Home
Introduction
Installation
Hello World
Data Types in PHP
Variables in PHP
Operators in PHP
Decision Making in PHP
Iterations in PHP
Functions in PHP
Arrays in PHP
Strings in PHP
Object Oriented PHP
Classes and Objects
Constructors
Inheritance
Object Interfaces
Static and Final
Advanced Features in PHP
GET and POST
Session in PHP
Cookies in PHP
Server Variables

Data Types in PHP
PHP supports 8 conventional data types:

ScalerCompoundSpecial
BooleanArrayresource
IntegerObjectNull
Float
String

Boolean (Truth Value)
Either TRUE or FALSE
Integer
A integer i.e. {...,-2,-1,,0,1,2,...}
Float (or Double)
Float is a real number
Strings
Series of characters
Array
Ordered map (Map-values are associated with keys)
Object
Object is an instance of a class.
Resource
Reference to external resource
NULL
Only value possible is NULL
Getting Data Type
You can determine the data type of a value using gettype($value) function. It will return string, value of which will be data type which may be any of the above value and can also be unknown.
If you need to check for only for a single data type, these functions can be used


<?php
$value = 12; // An integer
echo $value;
echo "<br>";  //To print the values in next line
echo gettype($value);
echo "<br>"; 
$value1 = 12.5;  //Float
echo gettype($value1);
echo "<br>";  //To print the values in next line
echo var_dump(is_int($value));  /*var_dump is used to display 
information about ab variable which includes its type and value*/
echo "<br>";
$value3 = "here is a string";
echo gettype($value3);

?>

Login to Track Your Progress