Type juggling refers to PHP’s ability to automatically change the data types of variables depending on the context in which they are used.
In the following example, the string “1” is added to the integer value 1. While this would cause an error in many other programming languages, PHP automatically converts the string into a matching integer value (here: 1) and calculates the result (here: 1 + 1 = 2).
<?php $a = (int)1; $b = (string)"1"; $c = $a + $b; var_dump($a, $b, $c); ?>
int(1) string(1) "1" int(2)PHP MCQ – Multiple Choice Questions and Answers – Basics – Part 1This collection of PHP Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer focuses on “PHP basic”. 1. In PHP, variables…Read More MCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More