0
0
PHPprogramming~20 mins

Implode and join in PHP - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Implode and Join Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1: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);
?>
Aapple-banana-cherry
Bapple,banana,cherry
Capple banana cherry
Dapplebanana cherry
Attempts:
2 left
💡 Hint
implode joins array elements with the string you give as the first argument.
Predict Output
intermediate
1: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);
?>
Apear grape melon
Bpear, grape, melon
Cpear,grape,melon
Dpear-grape-melon
Attempts:
2 left
💡 Hint
join() is an alias of implode(), so it works the same way.
Predict Output
advanced
1: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);
?>
A1234
B1 2 3 4
C1,2,3,4
DArray
Attempts:
2 left
💡 Hint
If the separator is an empty string, elements join without spaces or commas.
Predict Output
advanced
1: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);
?>
Aabc
Ba b c
Ca,b,c
DWarning: implode(): Invalid arguments passed
Attempts:
2 left
💡 Hint
implode expects the separator first, then the array.
🧠 Conceptual
expert
2: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);
?>
A13
B15
C14
D16
Attempts:
2 left
💡 Hint
Count letters plus spaces between words.