reference/array/functions/ksort.xml
2ca090342977839edca2f7f4e52305a1b5da6095
...
...
@@ -3,20 +3,23 @@
3
3
<refentry xml:id="function.ksort" xmlns="http://docbook.org/ns/docbook">
4
4
<refnamediv>
5
5
<refname>ksort</refname>
6
-
<refpurpose>Sort an array by key</refpurpose>
6
+
<refpurpose>Sort an array by key in ascending order</refpurpose>
7
7
</refnamediv>
8
8
<refsect1 role="description">
9
9
&reftitle.description;
10
10
<methodsynopsis>
11
-
<type>bool</type><methodname>ksort</methodname>
11
+
<type>true</type><methodname>ksort</methodname>
12
12
<methodparam><type>array</type><parameter role="reference">array</parameter></methodparam>
13
-
<methodparam choice="opt"><type>int</type><parameter>sort_flags</parameter><initializer>SORT_REGULAR</initializer></methodparam>
13
+
<methodparam choice="opt"><type>int</type><parameter>flags</parameter><initializer><constant>SORT_REGULAR</constant></initializer></methodparam>
14
14
</methodsynopsis>
15
15
<para>
16
-
Sorts an array by key, maintaining key to data correlations. This is
17
-
useful mainly for associative arrays.
16
+
Sorts <parameter>array</parameter> in place by keys
17
+
in ascending order.
18
18
</para>
19
+
&note.sort-unstable;
20
+
&note.reset-index;
19
21
</refsect1>
22
+

20
23
<refsect1 role="parameters">
21
24
&reftitle.parameters;
22
25
<para>
...
...
@@ -29,25 +32,37 @@
29
32
</para>
30
33
</listitem>
31
34
</varlistentry>
32
-
<varlistentry>
33
-
<term><parameter>sort_flags</parameter></term>
34
-
<listitem>
35
-
<para>
36
-
You may modify the behavior of the sort using the optional
37
-
parameter <parameter>sort_flags</parameter>, for details
38
-
see <function>sort</function>.
39
-
</para>
40
-
</listitem>
41
-
</varlistentry>
35
+
&sort.flags.parameter;
42
36
</variablelist>
43
37
</para>
44
38
</refsect1>
39
+

45
40
<refsect1 role="returnvalues">
46
41
&reftitle.returnvalues;
47
42
<para>
48
-
&return.success;
43
+
&return.true.always;
44
+
</para>
45
+
</refsect1>
46
+

47
+
<refsect1 role="changelog">
48
+
&reftitle.changelog;
49
+
<para>
50
+
<informaltable>
51
+
<tgroup cols="2">
52
+
<thead>
53
+
<row>
54
+
<entry>&Version;</entry>
55
+
<entry>&Description;</entry>
56
+
</row>
57
+
</thead>
58
+
<tbody>
59
+
&return.type.true;
60
+
</tbody>
61
+
</tgroup>
62
+
</informaltable>
49
63
</para>
50
64
</refsect1>
65
+

51
66
<refsect1 role="examples">
52
67
&reftitle.examples;
53
68
<para>
...
...
@@ -75,18 +90,55 @@ d = lemon
75
90
</screen>
76
91
</example>
77
92
</para>
93
+

94
+
<para>
95
+
<example>
96
+
<title><function>ksort</function> with <type>int</type> keys</title>
97
+
<programlisting role="php">
98
+
<![CDATA[
99
+
<?php
100
+
$a = [0 => 'First', 2 => 'Last', 1 => 'Middle'];
101
+
var_dump($a);
102
+
ksort($a);
103
+
var_dump($a);
104
+
?>
105
+
]]>
106
+
</programlisting>
107
+
&example.outputs;
108
+
<screen>
109
+
<![CDATA[
110
+
array(3) {
111
+
[0]=>
112
+
string(5) "First"
113
+
[2]=>
114
+
string(4) "Last"
115
+
[1]=>
116
+
string(6) "Middle"
117
+
}
118
+
array(3) {
119
+
[0]=>
120
+
string(5) "First"
121
+
[1]=>
122
+
string(6) "Middle"
123
+
[2]=>
124
+
string(4) "Last"
125
+
}
126
+
]]>
127
+
</screen>
128
+
</example>
129
+
</para>
78
130
</refsect1>
131
+

79
132
<refsect1 role="seealso">
80
133
&reftitle.seealso;
81
-
<para>
82
-
<simplelist>
83
-
<member><function>asort</function></member>
84
-
<member>&seealso.array.sorting;</member>
85
-
</simplelist>
86
-
</para>
134
+
<simplelist>
135
+
<member><function>sort</function></member>
136
+
<member><function>krsort</function></member>
137
+
<member>&seealso.array.sorting;</member>
138
+
</simplelist>
87
139
</refsect1>
88
-
</refentry>
89
140

141
+
</refentry>
90
142
<!-- Keep this comment at the end of the file
91
143
Local variables:
92
144
mode: sgml
93
145