php

PHP Type Juggling

Type juggling refers to PHP’s ability to automatically change the data types of variables depending on the context in which they are used.
 

Example :

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);
?>

Output:

int(1)
string(1) "1"
int(2)
PHP MCQ - Multiple Choice Questions and AnswersPHP 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 [st_adsense] mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *