Challenge - 5 Problems
Implode and Join Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:30remaining
What is the output of this PHP code using implode?
Look at the PHP code below. What will it print?
PHP
<?php $array = ['apple', 'banana', 'cherry']; echo implode('-', $array); ?>
Attempts:
2 left
💡 Hint
implode joins array elements with the string you give as the first argument.
✗ Incorrect
The implode function joins array elements into a string using the first argument as separator. Here, '-' is used, so the output is 'apple-banana-cherry'.
❓ Predict Output
intermediate1:30remaining
What does this PHP code output when using join()?
Check the PHP code below. What will it print?
PHP
<?php $fruits = ['pear', 'grape', 'melon']; echo join(', ', $fruits); ?>
Attempts:
2 left
💡 Hint
join() is an alias of implode(), so it works the same way.
✗ Incorrect
join() works like implode(). The separator ', ' is used, so the output is 'pear, grape, melon'.
❓ Predict Output
advanced1:30remaining
What is the output of implode with a numeric array and no separator?
What will this PHP code print?
PHP
<?php $numbers = [1, 2, 3, 4]; echo implode('', $numbers); ?>
Attempts:
2 left
💡 Hint
If the separator is an empty string, elements join without spaces or commas.
✗ Incorrect
implode with an empty string joins elements directly, so output is '1234'.
❓ Predict Output
advanced1:30remaining
What error or output does this code produce?
Consider this PHP code. What happens when you run it?
PHP
<?php $items = ['a', 'b', 'c']; echo implode($items); ?>
Attempts:
2 left
💡 Hint
implode expects the separator first, then the array.
✗ Incorrect
Calling implode with only one argument as an array causes a warning because the separator is missing.
🧠 Conceptual
expert2:00remaining
How many items are in the resulting string after implode?
Given this PHP code, how many characters will the output string have?
PHP
<?php $words = ['hi', 'there', 'friend']; $output = implode(' ', $words); echo strlen($output); ?>
Attempts:
2 left
💡 Hint
Count letters plus spaces between words.
✗ Incorrect
The words are 'hi' (2), 'there' (5), 'friend' (6). Spaces between words are 2. Total length = 2+1+5+1+6 = 14.