What is type casting and type juggling in PHP?
The way by which PHP can assign a particular data type for any variable is called typecasting. The required type of variable is mentioned in the parenthesis before the variable.
$str = "10"; // $str is now string
$bool = (boolean) $str; // $bool is now boolean
PHP does not support datatype for variable declaration. The type of the variable is changed automatically based on the assigned value and it is called type juggling.
$val = 5; // $val is now number
$val = "500" //$val is now string
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.