Bird
0
0

What will be the output of the following PHP code?

medium📝 Predict Output Q4 of 15
PHP - Variables and Data Types
What will be the output of the following PHP code?
$x = '7 oranges';
$y = 7;
var_dump($x == $y);
Astring(9) "7 oranges"
Bbool(false)
Cbool(true)
Dint(7)
Step-by-Step Solution
Solution:
  1. Step 1: Understand type juggling

    When using ==, PHP converts the string to a number if compared with an integer.
  2. Step 2: Convert string to number

    "7 oranges" converts to integer 7.
  3. Step 3: Compare values

    7 == 7 evaluates to true.
  4. Final Answer:

    bool(true) -> Option C
  5. Quick Check:

    String starting with number converts to that number [OK]
Quick Trick: Strings starting with digits convert to those digits [OK]
Common Mistakes:
  • Assuming string and integer are always different with ==
  • Expecting var_dump to output string instead of bool
  • Confusing === with == operator behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes