Data Types in PHP:

You already know that PHP is a loosely data type language. So you don’t have to declare data type of a variable. PHP has 7 types of data types they are as follows:

  • Integer
  • String
  • Boolean
  • Floating Type Numbers
  • Array
  • Object
  • Null

 Integers:

Integers are whole numbers and they don’t have any decimal point such as 6384.

There are some rules for defining an integer variable.

  • An integer declaration recommended at least one digit between (0-9)
  • An integer must not have a decimal number
  • An integer can not contain unnecessary blanks and commas
  • An integer can be positive or negative
  • There are 3 formats of integers: octal(base 8), decimal(base 10) and hexadecimal(base 16)

Example:

Strings:

In PHP string is a sequence of characters that is written in double quotes or single quotes.

Example:

Boolean:

In PHP the Boolean data type has two possible values either true or false. This data type most often use in conditional testing.

Example:

When condition is true

Example:

When condition is false

Floating Point Numbers or Double in PHP:

In PHP a floating point numbers or doubles means a number with decimal point or in exponential format of a number such as 5.3837.

Example:

Arrays:

May be already know what Array do in any Programming language but if you don’t know so please don’t worry about it. Array is nothing but a container to store multiple values in a single variable. To print an array you have to use “print_r()” function.

We will also cover this topic separately in this tutorial later.

Example:

Objects:

In PHP an object is used to store data and information both. Object must be declared explicitly. To use object first we need to create a class of that object for this “class” keyword is used.

After creating class we do all programming than we create an instance of that class and call that object by that instance or object.

Example:

Null Values:

In PHP if you assign a variable “null” so it will return “NULL” on browser. Null value is a special type and it only has one value that is “null”.

PHP null is very useful to identify that the variable is null or empty.

Example:

 

Leave a Reply

Your email address will not be published. Required fields are marked *