Menu

PHP join() Function – Convert an Array to a String
πŸ“°

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

DEV Community: phpΒ·YounΒ·8 days ago
#NDjJbUWh
#devto#dev#array#join#function
Reading 0:00
15s threshold

πŸ˜„ This post is based on the content from coding.courses .

Definition and Usage

(PHP Version | 4+)

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

The join() function is an alias of the implode() function. It works identically to the implode() function.

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 = join ( ', ' , $colors ); // Join with a ', ' delimiter

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

Enter fullscreen mode

Exit fullscreen mode

Syntax

join ( 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.