reference/array/functions/array-unique.xml
651fad6c6677036edd2871bb78199e17586a3acd
651fad6c6677036edd2871bb78199e17586a3acd
...
...
@@ -11,23 +11,21 @@
11
11
<methodsynopsis>
12
12
<type>array</type><methodname>array_unique</methodname>
13
13
<methodparam><type>array</type><parameter>array</parameter></methodparam>
14
-
<methodparam choice="opt"><type>int</type><parameter>sort_flags</parameter><initializer>SORT_STRING</initializer></methodparam>
14
+
<methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer><constant>SORT_STRING</constant></initializer></methodparam>
15
15
</methodsynopsis>
16
16
<para>
17
17
Takes an input <parameter>array</parameter> and returns a new array
18
18
without duplicate values.
19
19
</para>
20
20
<para>
21
-
Note that keys are preserved. <function>array_unique</function> sorts
22
-
the values treated as string at first, then will keep the first key
23
-
encountered for every value, and ignore all following keys. It does not
24
-
mean that the key of the first related value from the unsorted
25
-
<parameter>array</parameter> will be kept.
21
+
Note that keys are preserved. If multiple elements compare equal under
22
+
the given <parameter>flags</parameter>, then the key and value of
23
+
the first equal element will be retained.
26
24
</para>
27
25
<note>
28
26
<simpara>
29
27
Two elements are considered equal if and only if
30
-
<literal>(string) $elem1 === (string) $elem2</literal> i.e.
28
+
<literal>(string) $elem1 === (string) $elem2</literal>, i.e.
31
29
when the string representation is the same, the first element will be used.
32
30
</simpara>
33
31
</note>
...
...
@@ -46,14 +44,14 @@
46
44
</listitem>
47
45
</varlistentry>
48
46
<varlistentry>
49
-
<term><parameter>sort_flags</parameter></term>
47
+
<term><parameter>flags</parameter></term>
50
48
<listitem>
51
49
<para>
52
-
The optional second parameter <parameter>sort_flags</parameter>
53
-
may be used to modify the sorting behavior using these values:
50
+
The optional second parameter <parameter>flags</parameter>
51
+
may be used to modify the comparison behavior using these values:
54
52
</para>
55
53
<para>
56
-
Sorting type flags:
54
+
Comparison type flags:
57
55
<itemizedlist>
58
56
<listitem>
59
57
<simpara><constant>SORT_REGULAR</constant> - compare items normally
...
...
@@ -98,18 +96,13 @@
98
96
</thead>
99
97
<tbody>
100
98
<row>
101
-
<entry>5.2.10</entry>
99
+
<entry>7.2.0</entry>
102
100
<entry>
103
-
Changed the default value of <parameter>sort_flags</parameter> back to
104
-
<constant>SORT_STRING</constant>.
105
-
</entry>
106
-
</row>
107
-
<row>
108
-
<entry>5.2.9</entry>
109
-
<entry>
110
-
Added the optional <parameter>sort_flags</parameter> defaulting
111
-
to <constant>SORT_REGULAR</constant>. Prior to 5.2.9, this function used to sort
112
-
the array with <constant>SORT_STRING</constant> internally.
101
+
If <parameter>flags</parameter> is <constant>SORT_STRING</constant>,
102
+
formerly <parameter>array</parameter> has been copied and non-unique
103
+
elements have been removed (without packing the array afterwards), but
104
+
now a new array is built by adding the unique elements. This can result
105
+
in different numeric indexes.
113
106
</entry>
114
107
</row>
115
108
</tbody>
...
...
@@ -126,9 +119,11 @@
126
119
<programlisting role="php">
127
120
<![CDATA[
128
121
<?php
129
-
$input = array("a" => "green", "red", "b" => "green", "blue", "red");
122
+
123
+
$input = ["a" => "green", "red", "b" => "green", "blue", "red"];
130
124
$result = array_unique($input);
131
125
print_r($result);
126
+
132
127
?>
133
128
]]>
134
129
</programlisting>
...
...
@@ -151,9 +146,11 @@ Array
151
146
<programlisting role="php">
152
147
<![CDATA[
153
148
<?php
154
-
$input = array(4, "4", "3", 4, 3, "3");
149
+
150
+
$input = [4, "4", "3", 4, 3, "3"];
155
151
$result = array_unique($input);
156
152
var_dump($result);
153
+
157
154
?>
158
155
]]>
159
156
</programlisting>
...
...
@@ -170,15 +167,6 @@ array(2) {
170
167
</para>
171
168
</refsect1>
172
169
173
-
<refsect1 role="seealso">
174
-
&reftitle.seealso;
175
-
<para>
176
-
<simplelist>
177
-
<member><function>array_count_values</function></member>
178
-
</simplelist>
179
-
</para>
180
-
</refsect1>
181
-
182
170
<refsect1 role="notes">
183
171
&reftitle.notes;
184
172
<note>
...
...
@@ -189,8 +177,16 @@ array(2) {
189
177
</note>
190
178
</refsect1>
191
179
192
-
</refentry>
180
+
<refsect1 role="seealso">
181
+
&reftitle.seealso;
182
+
<para>
183
+
<simplelist>
184
+
<member><function>array_count_values</function></member>
185
+
</simplelist>
186
+
</para>
187
+
</refsect1>
193
188
189
+
</refentry>
194
190
<!-- Keep this comment at the end of the file
195
191
Local variables:
196
192
mode: sgml
197
193