Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
explode which splits strings, not joins arrays.✗ Incorrect
The implode function joins array elements into a string using the specified separator.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
explode which splits strings into arrays.✗ Incorrect
implode joins array elements into a string separated by the given string.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the order of arguments in
implode.✗ Incorrect
The implode function joins array elements into a string. Note the order: separator first, array second.
4fill in blank
hardComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong separator or wrong function name.
✗ Incorrect
Use implode with ':' as the separator to join the array elements.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong operators or wrong function order.
✗ Incorrect
Use = to join key and value, implode to join pairs, and & as separator.