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


Code
<?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


Code
<?php
// PHP Integer
$a = 3636; //Positive number
var_dump($a);
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


Code
<?php
// PHP Floating
$a = 36.36;
var_dump($a);
?>

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


Code
<?php
// PHP Boolean
$flag = true;
var_dump($flag);
?>

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


Code
<?php
// PHP Array
$student = array("John","Doe","Tom");
var_dump($student);
?>

Running Step.


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

PHP NULL:


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


Code
<?php
// PHP NULL
$a = 120 // Integer value
$a = null;
var_dump($a);
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