nerdexam
Zend

200-710 · Question #103

What is the output of the following code? var_dump (boolval ([]));

The correct answer is B. bool(false). Option B is correct because in PHP, boolval() follows the same type-casting rules as an explicit (bool) cast: an empty array always evaluates to false. Since [] contains no elements, boolval([]) returns false, and var_dump() displays the type and value, producing bool(false)…

Data Formats & Types

Question

What is the output of the following code? var_dump (boolval ([]));

Options

  • Abool(true)
  • Bbool(false)

How the community answered

(15 responses)
  • A
    27% (4)
  • B
    73% (11)

Explanation

Option B is correct because in PHP, boolval() follows the same type-casting rules as an explicit (bool) cast: an empty array always evaluates to false. Since [] contains no elements, boolval([]) returns false, and var_dump() displays the type and value, producing bool(false).

Option A is wrong because bool(true) would only be the result if the array contained at least one element (e.g., boolval([0]) or boolval(['a']) - even a single falsy element makes the array non-empty, thus truthy).

Memory tip: Think of it as "empty = false, non-empty = true" - the rule applies to arrays, strings ("" is false, "0" is false, anything else is true), and numbers (0 is false, everything else is true). An empty array [] is in the same "nothing there" category as 0 and "".

Topics

#boolval#empty array#boolean conversion#type casting

Community Discussion

No community discussion yet for this question.

Full 200-710 Practice