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 array | Array to string |
explode(separator, string) | implode(separator, array) |
| Splits at every separator | Puts 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 |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |