Bird
0
0

What is the output of this PHP code?

medium📝 Predict Output Q4 of 15
PHP - String Functions
What is the output of this PHP code?
$data = 'red|green|blue';
$colors = explode('|', $data);
echo count($colors);
A0
B1
C3
DError
Step-by-Step Solution
Solution:
  1. Step 1: Use explode() to split string

    The string 'red|green|blue' is split by '|' into ['red', 'green', 'blue'].
  2. Step 2: Count the resulting array elements

    There are 3 elements, so count($colors) returns 3.
  3. Final Answer:

    3 -> Option C
  4. Quick Check:

    explode splits string; count returns array size [OK]
Quick Trick: explode() splits; count() returns number of parts [OK]
Common Mistakes:
  • Expecting count to return string length
  • Using wrong delimiter
  • Forgetting explode returns array

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes