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.
Sample code:
1 2 | $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.
Sample code:
1 2 | $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.