Bird
0
0

What is the output of the following PHP code?

medium📝 Predict Output Q13 of 15
PHP - String Functions
What is the output of the following PHP code?
$arr = ['apple', 'banana', 'cherry'];
echo implode(' - ', $arr);
Aapple -banana -cherry
Bapple, banana, cherry
Capple - banana - cherry
Dapplebanana cherry
Step-by-Step Solution
Solution:
  1. Step 1: Understand implode with ' - ' separator

    The separator string ' - ' is placed between each array element.
  2. Step 2: Join the array elements

    Joining 'apple', 'banana', 'cherry' with ' - ' results in 'apple - banana - cherry'.
  3. Final Answer:

    apple - banana - cherry -> Option C
  4. Quick Check:

    implode with ' - ' joins elements with that exact separator [OK]
Quick Trick: Check the separator string carefully in output [OK]
Common Mistakes:
  • Confusing separator with comma
  • Missing spaces around separator
  • Assuming implode adds extra spaces

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes