Data Types in PHP 5

PHP Data types

PHP variables can be used to hold or store data of any kind.Data of different form can be used to perform differents tasks.

Supported PHP Data types  are

  • String
  • Integer
  • Float also refered to as Boolean
  • Array
  • Object
  • NULL
  • Resource

PHP String

String a group of characters eg”Programming in java”

A string in PHP can also refer to any text that has been eclosed inside two or one quote i.e double  “” or single ‘ quotes.


$text1= "I love Programming in PHP";
$text2 = 'I love Blogging';

echo $text1;
echo "<br>";
echo $text2;

SEE ALSO: PHP echo and print

PHP Integer

Data type is integer if its non-decimal.Ranges from -2,147,483,648 and 2,147,483,647.

Facts about Integers

1.Any integer should have one digit or more

2.No decimal point should be contained in integer

3.Integer can be + or – i.e -4 and 4

4.There are three formats for integers,These are (10-based)=decimal

16-based=hexadecimal and 8 based prefix=octal

PHP function  var_dump() when used returns the data type and value held by the variable



$num1 = 4583;

Output will be int(4583)

PHP Float

Float is a PHP Data type with a decimal point.Its a number which is in form of exponential.

For example ,Below code returns they type of data type num1 is by using function var_dump()

$num1= 34.375;

PHP Boolean

This data type only represents two states i.e true or false
These data types are used only to do conditional testing.Returned  by most PHP if else statements and while

PHP Array

Arrays are used to hold more than one value.
Example below is $animal array with all kind of animals.Using PHP var_dump() will output array values and the data type.
For Example:

$animals = array("lions","cow","goat");

PHP Object

Objects are data types that have  information and data  for processing that data.
Object are declared by using the class keyword.A class has both properties and methods

class Animal {
function Animal() {
$this-&gt;name = “All eat";

// create a new object
$dog = new Animal();

// output object properties
echo $dog-&gt;name;


This is a type of data type that can only have one value and that is NULL.

All variables created  that have no value when declared are assigned value NULL and if Variable has been assigned,it can be emptied using NULL


$text1 = “I love Programming In PHP";
$text1 = null;

PHP Resource

Resource are not real data types.Reference to function are stored in resource.A database call is example of resource data type

See My Next Lesson

PHP Strings

About the Author: Eric K

Kenyan Developer and Blogger with Interests in Java,Javascript,Node.js, Wordpress, Android, PHP and Making Money Online. Solving world problems through programming is my passion. Hire me: Email :