PHP TUTORIALPHP TutorialPHP InstallationPHP Hello WorldPHP Basic SyntaxPHP CommentsPHP VariablesPHP Variable ScopePHP ConstantsPHP StringsPHP OutputPHP Data TypesPHP Type CastingPHP OperatorsPHP ConditionalsPHP Shorthand ConditionalsPHP LoopsPHP Loop Control StructuresPHP FunctionsPHP String FunctionsPHP ArraysPHP Superglobal VariablesPHP in HTMLPHP AdvancedPHP Include and RequirePHP HTTP & HTTPSPHP RegexRegex IntroductionRegex PCRE SyntaxPHP PREG FunctionsPHP FormsPHP Forms IntroductionPHP Forms CreatingPHP Forms SecurityPHP Forms ValidationPHP Forms Required InputsPHP Forms StickyPHP Forms Advanced ValidationPHP Forms FinishingPHP OOPPHP OOP IntroductionPHP OOP ClassesPHP OOP PropertiesPHP OOP ObjectsPHP OOP MethodsPHP OOP $this KeywordPHP OOP Constructors and DestructorsPHP OOP VisibilityPHP OOP InheritancePHP OOP Abstract Classes and MethodsPHP OOP InterfacesPHP OOP TraitsPHP OOP ConstantsPHP OOP StaticPHP OOP NamespacesPHP OOP Autoloading

PHP Data Types

Variables can store different data types. In PHP, PHP chooses the appropriate data type for the variable automatically.

Normally, we need to store different types of data in variables to do different tasks.

There are several data types in PHP.

var_dump() Function

var_dump() function dumps information about a variable. The importance of this function is, it outputs the data type of the variable with its value. It is also a output function like echo()

PHP var_dump() Example

$x = 12;

Run Example ››

PHP Booleans

A Boolean is a variable that can have one of two possible values, true or false

Boolean is the simplest data type in PHP. It holds either true or false.

To specify a boolean, you can use constants true and false (Both are case-insensitive).

PHP Booleans Example

$a = true; // assign true to $a
$b = false; // assign false to $b


Run Example ››

PHP Integers

An integer is a number which is not a fraction; a whole number (..., -2, -1, 0, 1, 2, 3, ...)
An integer can either be a negative or a positive number

Four ways to specify an integer in following notations:

  • Specifying Integers in Decimal - base 10
  • Specifying Integers in Hexadecimal - base 16
  • Specifying Integers in Octal - base 8
  • Specifying Integers in Binary - base 2

This table shows how to specify an integer (128) in different notations.

NotationPreceded withExample

PHP Integers Example

// 128 in different notations
$a = 128; 			// decimal number

$a = -128; 			// a negative number

$a = 0x80; 			// hexadecimal number

$a = 0200; 			// octal number

$a = 0b10000000;	// binary number

Run Example ››

As a beginner, you will not frequently use hexadecimal, octal and binary notations. So, it is not compulsory to remember them now.

PHP Floats

A float is a number that can contain a fractional part (2.56, 1.24, 7E-10)

Floats are also known as "Double", "Real" or "Floating-Point Numbers".

PHP Floats Example

$a = 2.56;

$a = 2.56e3; // 2.56 multiplied by 3rd power of 10

$a = 2.56e-5; // 2.56 multiplied by -5th power of 10 

Run Example ››

PHP Strings

A string is any finite sequence of characters (letters, numerals, symbols, punctuation marks, etc.)

There are four ways to specify a string.

  • Single Quoted
  • Double Quoted
  • Heredoc Syntax
  • Nowdoc Syntax

We learned all of them in the strings chapter.

PHP Strings Example

$str = 'This is single quoted';
$str = "This is double quoted";

$str = <<<EOD
This is a heredoc example
This can be multiline

$str = <<<'EOD'
This is a nowdoc example
This can be multiline


Run Example ››

PHP Arrays

An array is a series of values

There are two ways to declare an array.

  • An array can be declared using the array() function.
  • An array can be declared wrapping with [ and ].

Elements of the arrays should be separated with a comma. And, elements can be any type you learn in this chapter.

PHP Arrays Example

$array = array('Apple', 'Banana', 'Orange', 'Mango');

$array = ['Apple', 'Banana', 'Orange', 'Mango'];

Run Example ››

Note: Array is a huge part in PHP. We will learn more about arrays in the Arrays Chapter.

PHP Objects

An object is a particular instance of a class where it can be a combination of variables, functions, and data structures.

Note: We will learn about objects in the Object Oriented Programming tutorial.


Null represents a variable with no value
  • Null means no value.
  • Null is not 0, false or any other value, it is null.
  • Null is case-insensitive. All Null, null and NULL are equal.

PHP Null Example

$var = null;

// unsetting variables with null
$text = 'Hello World';
$text = null; // now $text does not hold any value

Run Example ››
Visit PHP Help group to get some help from experts.
Profile Picture
Supun Kavinda
I'm the Founder of Hyvor, Web Developer, Physics Lover, Flutist, and a Table Tennis Player.
My Websites