Zend Certified PHP Engineer (ZCPE) Practice Test

Question: 1 / 400

What will the `count()` function return when applied to NULL?

1

NULL

0

The `count()` function in PHP is designed to count all elements in an array or something that implements the Countable interface. When `count()` is applied to a variable that is NULL, it treats NULL as an empty array. Since an empty array contains no elements, the `count()` function returns 0 in this case.

This behavior is consistent with the idea that when there are no elements to count, the result should logically equate to zero. Therefore, invoking `count()` on NULL results in a count of 0, indicating that there are no elements present.

Other options do not accurately reflect the behavior of the `count()` function. It does not return null, as this would imply an undefined or absent calculation, nor does it return 1, which would erroneously suggest the existence of one element. Returning false is also incorrect because false is a boolean value and does not represent a count. Thus, the correct answer is that `count()` returns 0 when applied to NULL.

Get further explanation with Examzify DeepDiveBeta

false

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy