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?
$a = 0;
$b = (bool)$a;
echo $b ? 'True' : 'False';
ATrue
BFalse
C0
D1
Step-by-Step Solution
Solution:
  1. Step 1: Cast integer 0 to boolean

    In PHP, 0 cast to boolean becomes false.
  2. Step 2: Evaluate ternary expression

    Since $b is false, the ternary outputs 'False'.
  3. Final Answer:

    The output is 'False'. -> Option B
  4. Quick Check:

    0 cast to bool = false [OK]
Quick Trick: Integer 0 cast to bool is false [OK]
Common Mistakes:
  • Assuming 0 becomes true
  • Confusing echo output with boolean value
  • Ignoring ternary operator behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes