nerdexam
Zend

200-710 · Question #102

What is the output of the following code? var_dump (boolval (-1));

The correct answer is A. bool(true). boolval(-1) returns true because PHP converts any non-zero integer to true - the sign doesn't matter. Only 0 (and equivalent falsy values like "", null, []) convert to false, making A correct. Why B is wrong: false would only result from boolval(0), not boolval(-1). A common…

Data Formats & Types

Question

What is the output of the following code? var_dump (boolval (-1));

Options

  • Abool(true)
  • Bbool(false)

How the community answered

(64 responses)
  • A
    84% (54)
  • B
    16% (10)

Explanation

boolval(-1) returns true because PHP converts any non-zero integer to true - the sign doesn't matter. Only 0 (and equivalent falsy values like "", null, []) convert to false, making A correct.

Why B is wrong: false would only result from boolval(0), not boolval(-1). A common misconception is that negative numbers are "false-like," but PHP's truthiness rule is simple: zero = false, everything else = true.

Memory tip: Think of it like a light switch - any non-zero value means "the light is on" (true). Only 0 turns the light off (false). Negative numbers are just as "on" as positive ones.

Topics

#boolval#type casting#boolean conversion

Community Discussion

No community discussion yet for this question.

Full 200-710 Practice