PHP - Data Types

A Data type specifies the amount of memory that allocates to a value associated with it. A type also determines the operations that you can perform on it.

PHP has ten primitive types including four scala types, four compound types, and two special types:

Scalar types

bool

int

float

string

Compound types

array

object

callable

iterable

Special types

resource

null

Scalar types

A variable is a scalar when it holds a single value of the type integer, float, string, or boolean.

Some Example:

$my_var = 1;

echo $my_var;

 

$my_var = 3.14;

echo $my_var;

 

$my_var ="Hypertext Pre Processor";

echo $my_var;

?>

Variables help separate data from the program algorithms.

The same algorithm can be used for different input data values.

For example, suppose that you are developing a calculator program that adds up two numbers, you can create two variables that accept the numbers then you use the variables names in the expression that does the addition.