reference/strings/functions/implode.xml
5dfba3d91fb059073e955aad7caf886faac652ce
...
...
@@ -1,6 +1,6 @@
1
1
<?xml version="1.0" encoding="utf-8"?>
2
2
<!-- $Revision$ -->
3
-
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.implode">
3
+
<refentry xml:id="function.implode" xmlns="http://docbook.org/ns/docbook">
4
4
<refnamediv>
5
5
<refname>implode</refname>
6
6
<refpurpose>Join array elements with a string</refpurpose>
...
...
@@ -10,24 +10,23 @@
10
10
&reftitle.description;
11
11
<methodsynopsis>
12
12
<type>string</type><methodname>implode</methodname>
13
-
<methodparam><type>string</type><parameter>glue</parameter></methodparam>
14
-
<methodparam><type>array</type><parameter>pieces</parameter></methodparam>
13
+
<methodparam><type>string</type><parameter>separator</parameter></methodparam>
14
+
<methodparam><type>array</type><parameter>array</parameter></methodparam>
15
15
</methodsynopsis>
16
+
<simpara>Alternative signature (not supported with named arguments):</simpara>
16
17
<methodsynopsis>
17
18
<type>string</type><methodname>implode</methodname>
18
-
<methodparam><type>array</type><parameter>pieces</parameter></methodparam>
19
+
<methodparam><type>array</type><parameter>array</parameter></methodparam>
20
+
</methodsynopsis>
21
+
<simpara>Legacy signature (deprecated as of PHP 7.4.0, removed as of PHP 8.0.0):</simpara>
22
+
<methodsynopsis>
23
+
<type>string</type><methodname>implode</methodname>
24
+
<methodparam><type>array</type><parameter>array</parameter></methodparam>
25
+
<methodparam><type>string</type><parameter>separator</parameter></methodparam>
19
26
</methodsynopsis>
20
27
<para>
21
-
Join array elements with a <parameter>glue</parameter> string.
28
+
Join array elements with a <parameter>separator</parameter> string.
22
29
</para>
23
-
<note>
24
-
<para>
25
-
<function>implode</function> can, for historical reasons, accept
26
-
its parameters in either order. For consistency with
27
-
<function>explode</function>, however, it may be less confusing
28
-
to use the documented order of arguments.
29
-
</para>
30
-
</note>
31
30
</refsect1>
32
31

33
32
<refsect1 role="parameters">
...
...
@@ -35,15 +34,15 @@
35
34
<para>
36
35
<variablelist>
37
36
<varlistentry>
38
-
<term><parameter>glue</parameter></term>
37
+
<term><parameter>separator</parameter></term>
39
38
<listitem>
40
39
<para>
41
-
Defaults to an empty string.
40
+
Optional. Defaults to an empty string.
42
41
</para>
43
42
</listitem>
44
43
</varlistentry>
45
44
<varlistentry>
46
-
<term><parameter>pieces</parameter></term>
45
+
<term><parameter>array</parameter></term>
47
46
<listitem>
48
47
<para>
49
48
The array of strings to implode.
...
...
@@ -58,10 +57,40 @@
58
57
&reftitle.returnvalues;
59
58
<para>
60
59
Returns a string containing a string representation of all the array
61
-
elements in the same order, with the glue string between each element.
60
+
elements in the same order, with the separator string between each element.
62
61
</para>
63
62
</refsect1>
64
63

64
+
<refsect1 role="changelog"><!-- {{{ -->
65
+
&reftitle.changelog;
66
+
<informaltable>
67
+
<tgroup cols="2">
68
+
<thead>
69
+
<row>
70
+
<entry>&Version;</entry>
71
+
<entry>&Description;</entry>
72
+
</row>
73
+
</thead>
74
+
<tbody>
75
+
<row>
76
+
<entry>8.0.0</entry>
77
+
<entry>
78
+
Passing the <parameter>separator</parameter> after the <parameter>array</parameter>
79
+
is no longer supported.
80
+
</entry>
81
+
</row>
82
+
<row>
83
+
<entry>7.4.0</entry>
84
+
<entry>
85
+
Passing the <parameter>separator</parameter> after the <parameter>array</parameter>
86
+
(i.e. using the legacy signature) has been deprecated.
87
+
</entry>
88
+
</row>
89
+
</tbody>
90
+
</tgroup>
91
+
</informaltable>
92
+
</refsect1><!-- }}} -->
93
+

65
94
<refsect1 role="examples">
66
95
&reftitle.examples;
67
96
<para>
...
...
@@ -71,13 +100,14 @@
71
100
<![CDATA[
72
101
<?php
73
102

74
-
$array = array('lastname', 'email', 'phone');
75
-
$comma_separated = implode(",", $array);
76
-

77
-
echo $comma_separated; // lastname,email,phone
103
+
$array = ['lastname', 'email', 'phone'];
104
+
var_dump(implode(",", $array)); // string(20) "lastname,email,phone"
78
105

79
106
// Empty string when using an empty array:
80
-
var_dump(implode('hello', array())); // string(0) ""
107
+
var_dump(implode('hello', [])); // string(0) ""
108
+

109
+
// The separator is optional:
110
+
var_dump(implode(['a', 'b', 'c'])); // string(3) "abc"
81
111

82
112
?>
83
113
]]>
84
114