Menu

PHP implode() Function – Convert an Array to a String
📰

PHP implode() Function – Convert an Array to a String

DEV Community: php·Youn·9 days ago
#ykIE4AjV
#devto#dev#array#string#implode
Reading 0:00
15s threshold

😄 This post is based on the content from coding.courses .

Definition and Usage

(PHP Version | 4+)

The implode() function joins array elements into a string using a custom delimiter.

This function returns a single string by joining each element of a given array with a specified delimiter.

Basic Example

$colors = [ 'red' , 'green' , 'blue' ]; $comma_separated = implode ( ', ' , $colors ); // Join with a ', ' delimiter

echo $comma_separated ; // Output: 'red, green, blue'

Enter fullscreen mode

Exit fullscreen mode

In this example, the elements of the array $colors are joined together into a single string, separated by a comma and a space ', '. The resulting string is 'red, green, blue'.

Syntax

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

Enter fullscreen mode

Exit fullscreen mode

Parameters

# $separator

Optional.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.