Multiple choice php

What does echo count (“123?) print out?

  1. 3

  2. false

  3. null

  4. 1

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

In PHP, count() is typically used on arrays. When used on a scalar value like a string, the behavior historically (and in some versions) was to return 1 (treating it as a single element array-like structure) or throw a warning in newer versions (PHP 7.2+). Given the options, 1 is the legacy/loose-type behavior.

AI explanation

PHP's count() function is meant for arrays/countable objects, but when it's called on a plain scalar like a string, PHP treats the argument as a single element and returns 1 (in the PHP versions where this doesn't outright error). So count("123") prints 1, not the string's length (which would need strlen()) and not 3.