HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

implode

Description

The implode of String for PHP joins array elements with a string.

Syntax

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

Parameters

separator

Optional. Defaults to an empty string.

array

The array of strings to implode.

Return

Returns a string containing a string representation of all the array elements in the same order, with the separator string between each element.

Examples

1 · array

<?

$array =
[
    "1",
    "2",
    "3"
];

$return = implode($array);

var_dump($return);
string(3) "123"

2 · separator array

<?

$separator = ",";
$array =
[
    "1",
    "2",
    "3"
];

$return = implode($separator, $array);

var_dump($return);
string(5) "1,2,3"

3 · empty

<?

$separator = ",";
$array = [];

$return = implode($separator, $array);

var_dump($return);
string(0) ""