PHP - Scalar Data types


PHP has eight primitive types, but for now, we will focus on its four scalar types:

Booleans true or false values
Integers numeric values without a decimal point, for example, 2 or 5
Floating point numbers or floatsnumbers with a decimal point, for example, 2.3
Stringscharacters which are surrounded by either single or double quotes, like 'this' or "that"


    $number = 123; /*from   w  ww. j av a  2 s . c o  m*/
    $number = 'abc'; 


Here, the code first assigns the value 123 to the variable $number.

As 123 is an integer, the type of the variable will be integer int.

After that, we assign another value to the same variable, this time a string.

The type of the variable changed from integer to string, and PHP did not complain at any time.

This is called type juggling.

Related Topics