PHP join() Function

Definition

The join() function, an alias of the implode() function, returns a string from the elements of an array.

Syntax

PHP join() Function has the following syntax.

join(separator,array)

Parameter

ParameterIs RequiredDescription
separatorOptional. What to put between the array elements. Default is "" (an empty string)
arrayRequired. The array to join to a string

Return

PHP join() Function returns a string from elements of an array.

Example 1

Join array elements with a string:


<?php
$arr = array('Hello','World!','from','java2s.com!');
echo join(" ",$arr);
?>

The code above generates the following result.

Example 2

Separate the array elements with different characters:


<?php//  w w w  .  ja va  2 s.c o m
$arr = array('Hello','World!','from','java2s.com!');
echo join(" ",$arr)."\n";
echo join("+",$arr)."\n";
echo join("-",$arr)."\n"; 
echo join("X",$arr);
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions