Javatpoint Logo
Javatpoint Logo

PHP string Implode() Function

PHP implode() is a string function, which joins the array elements in a string. It is a binary-safe function. In implode() function, parameters can be passed in any order.

The implode() function works same as the join() function and returns a string created from the elements of the array. Basically, this function joins all elements of array in one string.

Syntax

There are two syntax are available for implode() function, which are given below:

or

Join the array elements by $glue string parameter.

Parameters

There are two parameters can be passed in the implode() function, one of which is mandatory, and another one is optional. These parameters are as follows:

$glue (optional):

It is an optional and string type of parameter. It contains the value to join the array elements and form a string. Basically, $glue is used to join the string.

$pieces (mandatory):

This parameter contains the array of string to implode. The array elements are mandatory to pass in implode() function to join into one string.

Return Value

The implode() function returns the string formed from the array elements. The string will be formed in the same order as elements passed into array. The return type of this function is string.

Changes

After PHP version 7.4.0, passing the $glue parameter after the $pieces parameter has been deprecated.

Examples

Example 1:

In the below example, array elements are joined with + operator using implode() function.

Output:

Before using 'implode()' function:
array('Welcome', 'to', 'PHP', 'tutorial')

After using 'implode()' function:
Welcome+to+PHP+tutorial

Example 2:

Output:

Noida, Delhi, Gurugram
NoidaDelhiGurugram

Example 3:

In the below example, two arrays are joined together using implode() function.

Output:

Hello everyone! / Welcome to Javatpoint

Next TopicPHP String




Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA