PHP join() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
String

Definition

In PHP, join() joins array values into one string with a glue separator. It is an alias of implode().

Glue and array are required in the usual form. Prefer implode() in new code for consistency with the manual.

Syntax

Call join with glue and an array. Start with this line.

PHP
$csv = join(",", $parts);
CallWhat it does
join("-", ["a", "b"])Returns "a-b".
implode(",", $parts)Same behavior as join().

join() and implode() are interchangeable. explode() splits a string into an array.

Library declarations
PHP
join(string $separator, array $array): string

Parameters

ParameterDescription
separatorRequired. The glue inserted between array items.
arrayRequired. The array of values to join.

Return Value

Return ValueDescription
stringA single string made from the array items.

PHP Examples

Example 1 — Comma-Separated Fruit List

The classic join pattern—readable English for “stick these together.”

PHP
<?php
$fruits = ['apple', 'banana', 'orange'];
$result = join(', ', $fruits);

echo $result . "\n";
?>

How It Works

  1. Start with an array. Three fruit names as values.
  2. Pick glue. ", " goes between neighbors.
  3. Call join. Returns one string with no trailing separator.
  4. Read the name. join describes the action clearly for beginners.

Example 2 — join() === implode()

Prove the alias: same input, same output, same identity check.

PHP
<?php
$tags = ['php', 'mysql', 'html'];

$viaJoin    = join(' | ', $tags);
$viaImplode = implode(' | ', $tags);

echo "join():    $viaJoin\n";
echo "implode(): $viaImplode\n";
echo "Same:      " . ($viaJoin === $viaImplode ? "yes\n" : "no\n");
?>

How It Works

  1. Same glue and array. Both calls use ' | ' and $tags.
  2. Same string. Output lines match character for character.
  3. === is true. Not “similar”—identical return values.
  4. Pick a convention. Behavior never differs; style might.

Example 3 — Path Segments and Empty Glue

Join with / for simple URL-like paths, or omit the separator to concatenate.

PHP
<?php
$segments = ['api', 'v1', 'users', '42'];
$url      = join('/', $segments);

$chars = ['H', 'e', 'l', 'l', 'o'];
$word  = join($chars);

echo "URL:  /$url\n";
echo "Word: $word\n";
?>

How It Works

  1. Slash glue. Segments become a path-style string.
  2. Leading slash. Added in echo—not by join itself.
  3. One-arg form. join($chars) uses an empty separator.
  4. Result. Letters stick together as Hello.

Frequently Asked Questions

join() joins array elements into one string with a separator between each value. It is an alias of implode()—same parameters, same return value, identical behavior.
string join(string $separator, array $array). You can also call join(array $array) with one argument to concatenate with no separator. Argument order matches implode() in PHP 8+.
There is no functional difference. join() is an alias of implode(). implode() is more common in PHP codebases; join() reads naturally in English and matches naming in JavaScript and other languages.
Either is correct. Many teams standardize on implode() for consistency with PHP documentation examples. Use join() when it reads more clearly in your code—just stay consistent within a project.
It returns an empty string, same as implode(). A single-element array returns that element with no separator added.

Next: lcfirst()

Make the first character of a string lowercase.

lcfirst() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful