PHP Operators

PHP Operators

Most of the operators from above table should be self explanatory, so I'm not going to cover them. Though I do want to go over "Identify" since it may not be so obvious.

Identity Operator

What the identity operator will do is convert a string float or integer value to an actual float or integer value. Here is what I mean by string float or integer:

$string_float = '3.5'; var_dump($num); //output: string(3) "3.5" $string_integer = '100'; var_dump($num); //output: string(3) "100"

As you can see both variables from above are of string data type when output using var_dump() function. Let's now use the identity operator on both to see what happens:

$string_float = '3.5'; var_dump(+$num); //output: float(3.5) $string_integer = '100'; var_dump(+$num); //output: int(100)

PHP has now converted both strings to their appropriate types: float and integer. This operator is designed for converting valid string values of integer and float which are enclosed in quotes to their appropriate values and there will be situations when it may be useuful.