Web Analytics

PHP implode() Function

String Function PHP 4+

The implode() function joins array elements into a single string using a separator.

Syntax

implode(string $separator, array $array): string

Parameters

ParameterTypeDescription
$separatorstringThe glue string between elements
$arrayarrayThe 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