Implicit Type Casting in PHP

Notes:

Type Casting in PHP

PHP Type Casting:
Converting one type of data value to another type is called as type casting.
where: data value can be a literal, variable name or constant name

There are 2 types of type casting:
Implicit type casting (Coercion): Done by PHP Engine
Explicit type casting (Conversion): Done by programmers

Implicit type casting:
If required PHP engine automatically converts one type of data value to another type; which is known as implicit type casting.

Example Code:
echo 2 + 4.3; // 2.0 + 4.3 = 6.3
echo "<br/>";

echo "22manjunath" + 22; // 22 + 22 = 44
echo "<br/>";

echo "manjunath22" + 22; // 0 + 22 = 22
echo "<br/>";

echo 2 * "4a"; // 2 * 4 = 8
echo "<br/>";

echo 2 * "a2"; // 2 * 0 =0
echo "<br/>";

echo 4 * 2.5; // 4.0 * 2.5 = 10.0
echo "<br/>";

echo "2" + "2"; // 2 + 2 = 4
echo "<br/>";

Note:
While performing any type of numerical calculations; if a string starts with valid number then it is extracted out, otherwise string is converted to 0.

Interview Questions:

1. PHP stands for ______________
a. Hypertext Preprocessor
b. Preprocessor Hypertext
c. Personal Home Processor
d. Personal Hypertext processor
Ans: a