Data Types In PHP

by Hiroshi on June 19, 2008

in Data Types, PHP Basics

Data types are many e.g. Boolean, Integer, Double (or float), String and there might be some more…really!

Data Types

Boolean

A truth value; can be either TRUE or FALSE.

Integer

A number value; can be a positive or negative whole number.

Double (or float)

A floating-point number value; can be any decimal number.

String

An alphanumeric value; can contain any number of ASCII characters.

This is how we can find datatype using PHP.

<?php
$value = 7.2;
echo gettype($value);
// OUTPUT: Double
?>
<?php
$value = 7;
echo gettype($value);
// OUTPUT: Integer
?>
<?php
$value = "javed hiroshi";
echo gettype($value);
// OUTPUT: String
?>
<?php
$value = true;
echo gettype($value);
// OUTPUT: Boolean
?>
<?php
$value =  "2nd January 2005";
settype($value, "integer");
echo $value;
// OUTPUT: 2
// Selected data type
?>

Related Posts

Previous post:

Next post: