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,7 +102,7 @@
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
108
More arrays, optionally followed by sort order and flags. Only elements
...
...
@@ -120,38 +122,6 @@
120
122
</para>
121
123
</refsect1>
122
124

123
-
<refsect1 role="changelog">
124
-
&reftitle.changelog;
125
-
<para>
126
-
<informaltable>
127
-
<tgroup cols="2">
128
-
<thead>
129
-
<row>
130
-
<entry>&Version;</entry>
131
-
<entry>&Description;</entry>
132
-
</row>
133
-
</thead>
134
-
<tbody>
135
-
<row>
136
-
<entry>5.4.0</entry>
137
-
<entry>
138
-
The <constant>SORT_NATURAL</constant> and <constant>SORT_FLAG_CASE</constant>
139
-
were added to <parameter>array1_sort_flags</parameter> as possible sort flags.
140
-
</entry>
141
-
</row>
142
-
<row>
143
-
<entry>5.3.0</entry>
144
-
<entry>
145
-
The <constant>SORT_LOCALE_STRING</constant> was added to
146
-
<parameter>array1_sort_flags</parameter> as possible sort flags.
147
-
</entry>
148
-
</row>
149
-
</tbody>
150
-
</tgroup>
151
-
</informaltable>
152
-
</para>
153
-
</refsect1>
154
-

155
125
<refsect1 role="examples">
156
126
&reftitle.examples;
157
127
<para>
...
...
@@ -294,6 +264,10 @@ foreach ($data as $key => $row) {
294
264
$edition[$key] = $row['edition'];
295
265
}
296
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
+

297
271
// Sort the data with volume descending, edition ascending
298
272
// Add $data as the last parameter, to sort by the common key
299
273
array_multisort($volume, SORT_DESC, $edition, SORT_ASC, $data);
300
274