Php Data Types

It is a set of value that has some operations associated with it and also provides the information about the memory. In general term data type defines the ttype of data a variable can hold.

Integers

They are whole numbers, without a decimal point, like 4195. They are the simplest type .they correspond to simple whole numbers, both positive and negative. Integers can be assigned to variables, or they can be used in expressions.

Integer can be in decimal (base 10), octal (base 8), and hexadecimal (base 16) format. Decimal format is the default, octal integers are specified with a leading 0, and hexadecimals have a leading 0x.

Example :-

Result

Hello world!
Hello world!

Doubles

They like 3.14159 or 49.1. By default, doubles print with the minimum number of decimal places needed.

Example :-

Result

2.28888 + 2.21112 = 4.5

Boolean

They have only two possible values either true or false. PHP provides a couple of constants especially for use as Booleans: TRUE and FALSE.

Example

Null

NULL is a special type that only has one value: NULL. To give a variable the NULL value.The special constant NULL is capitalized by convention, but actually it is case insensitive.

Example

Strings

They are sequences of characters, like "PHP supports string operations". Following are valid examples of string Singly quoted strings are treated almost literally, whereas doubly quoted strings replace variables with their values as well as specially interpreting certain character sequences.

Example

Result

My $variable will not print!
My name will print

Array

An array stores multiple values in one single variable.

Example

Result

array(3) { [0]=> string(5) "Volvo" [1]=> string(3) "BMW" [2]=> string(6) "Toyota" }

Objects

An object is a data type which stores data and information on how to process that data.First we must declare a class of object. For this, we use the class keyword. A class is a structure that can contain properties and methods.

Example

Result

VW