0
0
PHPprogramming~15 mins

Implode and join in PHP - Mini Project: Build & Apply

Choose your learning style9 modes available
Implode and join
📖 Scenario: You are working on a simple PHP script to combine a list of fruits into a single string. This is useful when you want to display items separated by commas or other characters.
🎯 Goal: Build a PHP script that uses implode (also known as join) to combine an array of fruits into a single string separated by commas.
📋 What You'll Learn
Create an array called $fruits with the exact values: 'apple', 'banana', 'cherry', 'date'
Create a variable called $separator and set it to a comma followed by a space: ', '
Use the implode function with $separator and $fruits to create a string called $fruitString
Print the value of $fruitString
💡 Why This Matters
🌍 Real World
Joining array elements into a string is common when displaying lists, creating CSV lines, or formatting output for users.
💼 Career
Understanding how to combine array data into strings is useful for web developers working with PHP to generate dynamic content.
Progress0 / 4 steps
1
Create the fruits array
Create an array called $fruits with these exact values: 'apple', 'banana', 'cherry', 'date'
PHP
Need a hint?

Use square brackets [] to create the array and separate items with commas.

2
Create the separator variable
Create a variable called $separator and set it to the string ', ' (a comma followed by a space).
PHP
Need a hint?

Remember to put the comma and space inside quotes to make it a string.

3
Use implode to join the fruits
Use the implode function with $separator and $fruits to create a string called $fruitString.
PHP
Need a hint?

The implode function takes the separator first, then the array.

4
Print the joined string
Print the value of $fruitString using echo.
PHP
Need a hint?

Use echo to display the string on the screen.