• Tutorial List

PHP Data Types

Last updated May 15, 2020
PHP Data Types

What are the PHP data types?

When you assign a value in a variable, the value of that variable can be of different types, such as number, text, etc. This is called PHP Data Types.

How many data types are supported in PHP?

PHP supports the following data types –

  • String
  • Integer
  • Float (floating-point numbers)
  • Boolean
  • Array
  • Object
  • NULL
  • Resource

PHP Data Types with a short description


A string is a sequence of characters, that are inside a single or double quote.

	$x = "This is a String";
	$y = 'Another String';


An integer is a non-decimal number.

 	$x = 458; 


A Float is a number with a decimal point.

 	$x = 10.5;


True or False (It is used in conditional testing).

 	$x = true;
	$y = false;


An array is a Collection of multiple values.

 	$x = array("value1","value2"); 


An object is an instance of a class.

class Elephant{
    public function legs(){
      	return "4 Legs";
    public function tail(){
      	return "1 Tail";

$elephant = new Elephant();

// output is - 4 Legs
echo $elephant->legs();


If there is a NULL data type in a variable, then that means the variable does not have any value.

	$x = NULL;

📝 If a variable is declared without any value, then the variable is automatically assigned the NULL value.


The resource type is not the actual data type. It is a storage of references to functions or to external PHP resources. Such as Database Connection.