0
0
PHPprogramming~10 mins

Implode and join in PHP - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to join array elements with a comma.

PHP
<?php
$array = ['apple', 'banana', 'cherry'];
$result = [1](',', $array);
echo $result;
?>
Drag options to blanks, or click blank then click option'
Aarray_merge
Bjoin
Cimplode
Dexplode
Attempts:
3 left
💡 Hint
Common Mistakes
Using explode which splits strings, not joins arrays.
2fill in blank
medium

Complete the code to join array elements with a space.

PHP
<?php
$words = ['Hello', 'world', '!'];
$text = [1](' ', $words);
echo $text;
?>
Drag options to blanks, or click blank then click option'
Aexplode
Bimplode
Cjoin
Darray_push
Attempts:
3 left
💡 Hint
Common Mistakes
Using explode which splits strings into arrays.
3fill in blank
hard

Fix the error in the code to correctly join array elements with a dash.

PHP
<?php
$parts = ['2024', '06', '15'];
$date = [1]('-', $parts);
echo $date;
?>
Drag options to blanks, or click blank then click option'
Aimplode
Bjoin
Cexplode
Darray_merge
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the order of arguments in implode.
4fill in blank
hard

Complete the code to join array elements with a colon and assign to variable.

PHP
<?php
$time = ['12', '30', '45'];
$joined = [1](':', $time);
echo $joined;
?>
Drag options to blanks, or click blank then click option'
Aimplode
B:
C-
Djoin
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong separator or wrong function name.
5fill in blank
hard

Fill all three blanks to join array keys and values with '=' and pairs with '&'.

PHP
<?php
$params = ['name' => 'John', 'age' => 30];
$pairs = [];
foreach ($params as $key => $value) {
    $pairs[] = $key . '[1]' . $value;
}
$query = [2]('[3]', $pairs);
echo $query;
?>
Drag options to blanks, or click blank then click option'
A.
Bimplode
C&
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong operators or wrong function order.