PHP Data Types

PHP Variables Scope Previous Next PHP Operators

In programming language variables are required to store information of data.

Variables have different data types.

PHP have following data types give below.

  1. String
  2. Integer
  3. Float (floating point numbers)
  4. Boolean
  5. Array
  6. Object
  7. NULL
  8. Resource

PHP String

A string is any sequence of characters or text inside single or double quotes.

Here is the code of string data types.

Filename: php / string.php

// PHP String 
$s="Hello PHP String";
$s1='Hello PHP String';
echo $s."
"; echo $s1; ?>

Running Step.

Type Url - https://localhost/php/string.php

PHP Integer

An integer data type is any positive or negative non-decimal number between -2,147,483,648 and 2,147,483,647.

An integers can be specified in three formats given below.

  1. Decimal
  2. Hexadecimal
  3. Octal

Here is the code of integer data types.

Filename: php / integer.php

// PHP Integer
$a = 3636; //Positive number
echo "
"; $b = -3636; //Negative number var_dump($b); ?>

Running Step.

Type Url - https://localhost/php/integer.php

PHP Float (Floating Point Number)

A float number is a number with a decimal point.

Filename: php / floating.php

// PHP Floating
$a = 36.36;

Running Step.

Type Url - https://localhost/php/floating.php

PHP Boolean

A boolean data type can take on of the possible two values: true or false.

Filename: php / boolean.php

// PHP Boolean
$flag = true;

Running Step.

Type Url - https://localhost/php/boolean.php

PHP Array

An array is used when multiple values have to be stored for a single variable.

Filename: php / array.php

// PHP Array
$student = array("John","Doe","Tom");

Running Step.

Type Url - https://localhost/php/array.php


A variable of data type NULL has no value assigned to it.

When $a a variable is created with no value stored in it, it is automatically assigned a null value.

If one wants to empty a variable, then its value can be set to null.

Filename: php / null.php

$a = 120 // Integer value
$a = null;
echo "
"; $b = "Hello World"; // String value $b = null; var_dump($b); ?>

Running Step.

Type Url - https://localhost/php/null.php

PHP Resource:

A resource is not an actual data type. It is a reference to a functions, objects or resources external to it.

For e.g. A resource data type in a php program might refer to a field in a database.

Tags: PHP

Was this helpful ?

Related Code

Popular Code

Latest Code