PHP implode() Function
The implode() function joins array elements into a single string using a separator.
Syntax
implode(string $separator, array $array): string
Parameters
| Parameter | Type | Description |
|---|---|---|
$separator | string | The glue string between elements |
$array | array | The array of strings to join |
Return Value
Returns a string containing all array elements joined by the separator.
Try It Online
Output
Click Run to execute your code
More Examples
Create CSV String
<?php
$data = ["John", "25", "NYC"];
echo implode(",", $data);
// "John,25,NYC"
?>
SQL IN Clause
<?php
$ids = [1, 2, 3, 4];
$sql = "SELECT * FROM users WHERE id IN (" . implode(",", $ids) . ")";
echo $sql;
?>
No Separator
<?php
$chars = ["H", "e", "l", "l", "o"];
echo implode("", $chars); // "Hello"
?>
Tip:
join() is an alias of implode() - they work identically.
Common Use Cases
- Creating CSV output
- Building SQL queries
- Generating breadcrumbs
- Creating URL paths
Related Functions
- explode() - Split string to array
join()- Alias of implode- array_values() - Get array values
Enjoying these tutorials?