reference/array/functions/array-multisort.xml
6a6f43d1c490a57b452656db285de6d136055ed2
...
...
@@ -12,7 +12,7 @@
12
12
<methodparam><type>array</type><parameter role="reference">array1</parameter></methodparam>
13
13
<methodparam choice="opt"><type>mixed</type><parameter>array1_sort_order</parameter><initializer>SORT_ASC</initializer></methodparam>
14
14
<methodparam choice="opt"><type>mixed</type><parameter>array1_sort_flags</parameter><initializer>SORT_REGULAR</initializer></methodparam>
15
-
<methodparam choice="opt"><type>mixed</type><parameter>...</parameter></methodparam>
15
+
<methodparam rep="repeat"><type>mixed</type><parameter>rest</parameter></methodparam>
16
16
</methodsynopsis>
17
17
<para>
18
18
<function>array_multisort</function> can be used to sort several
...
...
@@ -23,6 +23,8 @@
23
23
Associative (<type>string</type>) keys will be maintained, but numeric
24
24
keys will be re-indexed.
25
25
</para>
26
+
&note.sort-unstable;
27
+
&note.reset-index;
26
28
</refsect1>
27
29

28
30
<refsect1 role="parameters">
...
...
@@ -100,10 +102,12 @@
100
102
</listitem>
101
103
</varlistentry>
102
104
<varlistentry>
103
-
<term><parameter>...</parameter></term>
105
+
<term><parameter>rest</parameter></term>
104
106
<listitem>
105
107
<para>
106
-
More arrays, optionally followed by sort order and flags.
108
+
More arrays, optionally followed by sort order and flags. Only elements
109
+
corresponding to equivalent elements in previous arrays are compared.
110
+
In other words, the sort is lexicographical.
107
111
</para>
108
112
</listitem>
109
113
</varlistentry>
...
...
@@ -118,38 +122,6 @@
118
122
</para>
119
123
</refsect1>
120
124

121
-
<refsect1 role="changelog">
122
-
&reftitle.changelog;
123
-
<para>
124
-
<informaltable>
125
-
<tgroup cols="2">
126
-
<thead>
127
-
<row>
128
-
<entry>&Version;</entry>
129
-
<entry>&Description;</entry>
130
-
</row>
131
-
</thead>
132
-
<tbody>
133
-
<row>
134
-
<entry>5.4.0</entry>
135
-
<entry>
136
-
The <constant>SORT_NATURAL</constant> and <constant>SORT_FLAG_CASE</constant>
137
-
were added to <parameter>array1_sort_flags</parameter> as possible sort flags.
138
-
</entry>
139
-
</row>
140
-
<row>
141
-
<entry>5.3.0</entry>
142
-
<entry>
143
-
The <constant>SORT_LOCALE_STRING</constant> was added to
144
-
<parameter>array1_sort_flags</parameter> as possible sort flags.
145
-
</entry>
146
-
</row>
147
-
</tbody>
148
-
</tgroup>
149
-
</informaltable>
150
-
</para>
151
-
</refsect1>
152
-
153
125
<refsect1 role="examples">
154
126
&reftitle.examples;
155
127
<para>
...
...
@@ -260,7 +232,7 @@ volume | edition
260
232
</screen>
261
233
<para>
262
234
The data as an array, called <varname>data</varname>. This would usually,
263
-
for example, be obtained by looping with <function>mysql_fetch_assoc</function>.
235
+
for example, be obtained by looping with <function>mysqli_fetch_assoc</function>.
264
236
</para>
265
237
<programlisting role="php">
266
238
<![CDATA[
...
...
@@ -292,6 +264,10 @@ foreach ($data as $key => $row) {
292
264
$edition[$key] = $row['edition'];
293
265
}
294
266

267
+
// you can use array_column() instead of the above code
268
+
$volume = array_column($data, 'volume');
269
+
$edition = array_column($data, 'edition');
270
+

295
271
// Sort the data with volume descending, edition ascending
296
272
// Add $data as the last parameter, to sort by the common key
297
273
array_multisort($volume, SORT_DESC, $edition, SORT_ASC, $data);
...
...
@@ -325,7 +301,7 @@ volume | edition
325
301
with a lowercase letter.
326
302
</para>
327
303
<para>
328
-
To perform a case insensitive search, force the sorting order to be
304
+
To perform a case insensitive sort, force the sorting order to be
329
305
determined by a lowercase copy of the original array.
330
306
</para>
331
307
<programlisting role="php">
332
308