What is the difference between explode() and implode() in PHP?

explode() breaks a string into an array. implode() joins the elements of an array into a string. They do opposite work.

explode()implode()
String to arrayArray to string
explode(separator, string)implode(separator, array)
Splits at every separatorPuts the separator between elements
<?php
$text = "apple,banana,cherry";

$fruits = explode(",", $text);
print_r($fruits);

echo implode(" - ", $fruits);
?>

Output:

Tutorials Class - Output Window

Array
(
[0] => apple
[1] => banana
[2] => cherry
)
apple – banana – cherry

Learn more in PHP explode() Function and PHP implode() Function.


Learn more about the similar topics:
Tutorials
PHP String Handling
PHP explode() Function
PHP strpos() Function
PHP implode() Function
Exercises & Assignments
Write a PHP program to reverse the string
Write a PHP program to find the length of the string
Write a PHP program to count the words in the string
Write a PHP program to convert a string into uppercase
Interview Questions & Answers
How will you concatenate two strings in PHP?
What is the difference between single quote and double quote string in PHP?
Why we use PHP String functions trim(), ltrim() and rtrim()?
What PHP Function is used to find position of a string?
What is the use of ucwords() PHP String function?
What is the use of str_replace() PHP String function?
How to find String Length in PHP?