1
0
mirror of https://github.com/php/doc-en.git synced 2026-03-25 00:02:17 +01:00

Add more implode examples

Closes GH-1195.
This commit is contained in:
Kamil Tekiela
2021-12-13 13:07:29 +00:00
committed by GitHub
parent 917c06eac8
commit 5dfba3d91f

View File

@@ -37,7 +37,7 @@
<term><parameter>separator</parameter></term>
<listitem>
<para>
Defaults to an empty string.
Optional. Defaults to an empty string.
</para>
</listitem>
</varlistentry>
@@ -100,13 +100,14 @@
<![CDATA[
<?php
$array = array('lastname', 'email', 'phone');
$comma_separated = implode(",", $array);
echo $comma_separated; // lastname,email,phone
$array = ['lastname', 'email', 'phone'];
var_dump(implode(",", $array)); // string(20) "lastname,email,phone"
// Empty string when using an empty array:
var_dump(implode('hello', array())); // string(0) ""
var_dump(implode('hello', [])); // string(0) ""
// The separator is optional:
var_dump(implode(['a', 'b', 'c'])); // string(3) "abc"
?>
]]>