reference/array/functions/array-unshift.xml
caf779183ee9860b48c74c8994fb944039b6b56f
...
...
@@ -10,16 +10,16 @@
10
10
<methodsynopsis>
11
11
<type>int</type><methodname>array_unshift</methodname>
12
12
<methodparam><type>array</type><parameter role="reference">array</parameter></methodparam>
13
-
<methodparam><type>mixed</type><parameter>var</parameter></methodparam>
14
-
<methodparam choice="opt"><type>mixed</type><parameter>...</parameter></methodparam>
13
+
<methodparam rep="repeat"><type>mixed</type><parameter>values</parameter></methodparam>
15
14
</methodsynopsis>
16
15
<para>
17
16
<function>array_unshift</function> prepends passed elements to the front
18
17
of the <parameter>array</parameter>. Note that the list of elements is
19
18
prepended as a whole, so that the prepended elements stay in the same
20
19
order. All numerical array keys will be modified to start counting from
21
-
zero while literal keys won't be touched.
20
+
zero while literal keys won't be changed.
22
21
</para>
22
+
&note.reset-index;
23
23
</refsect1>
24
24
<refsect1 role="parameters">
25
25
&reftitle.parameters;
...
...
@@ -34,10 +34,10 @@
34
34
</listitem>
35
35
</varlistentry>
36
36
<varlistentry>
37
-
<term><parameter>var</parameter></term>
37
+
<term><parameter>values</parameter></term>
38
38
<listitem>
39
39
<para>
40
-
The prepended variable.
40
+
The values to prepend.
41
41
</para>
42
42
</listitem>
43
43
</varlistentry>
...
...
@@ -50,6 +50,32 @@
50
50
Returns the new number of elements in the <parameter>array</parameter>.
51
51
</para>
52
52
</refsect1>
53
+

54
+
<refsect1 role="changelog">
55
+
&reftitle.changelog;
56
+
<para>
57
+
<informaltable>
58
+
<tgroup cols="2">
59
+
<thead>
60
+
<row>
61
+
<entry>&Version;</entry>
62
+
<entry>&Description;</entry>
63
+
</row>
64
+
</thead>
65
+
<tbody>
66
+
<row>
67
+
<entry>7.3.0</entry>
68
+
<entry>
69
+
This function can now be called with only one parameter. Formerly, at
70
+
least two parameters have been required.
71
+
</entry>
72
+
</row>
73
+
</tbody>
74
+
</tgroup>
75
+
</informaltable>
76
+
</para>
77
+
</refsect1>
78
+

53
79
<refsect1 role="examples">
54
80
&reftitle.examples;
55
81
<para>
...
...
@@ -58,22 +84,115 @@
58
84
<programlisting role="php">
59
85
<![CDATA[
60
86
<?php
61
-
$queue = array("orange", "banana");
87
+
$queue = [
88
+
"orange",
89
+
"banana"
90
+
];
91
+

62
92
array_unshift($queue, "apple", "raspberry");
63
-
print_r($queue);
93
+
var_dump($queue);
64
94
?>
65
95
]]>
66
96
</programlisting>
67
97
&example.outputs;
68
98
<screen role="php">
69
99
<![CDATA[
70
-
Array
71
-
(
72
-
[0] => apple
73
-
[1] => raspberry
74
-
[2] => orange
75
-
[3] => banana
76
-
)
100
+
array(4) {
101
+
[0] =>
102
+
string(5) "apple"
103
+
[1] =>
104
+
string(9) "raspberry"
105
+
[2] =>
106
+
string(6) "orange"
107
+
[3] =>
108
+
string(6) "banana"
109
+
}
110
+
]]>
111
+
</screen>
112
+
</example>
113
+
</para>
114
+
<para>
115
+
<example>
116
+
<title>Usage with associative arrays</title>
117
+
<para>
118
+
If one associative array is prepended to another associative array,
119
+
the prepended array is numerically indexed into the former array.
120
+
</para>
121
+
<programlisting role="php">
122
+
<![CDATA[
123
+
<?php
124
+
$foods = [
125
+
'apples' => [
126
+
'McIntosh' => 'red',
127
+
'Granny Smith' => 'green',
128
+
],
129
+
'oranges' => [
130
+
'Navel' => 'orange',
131
+
'Valencia' => 'orange',
132
+
],
133
+
];
134
+
$vegetables = [
135
+
'lettuce' => [
136
+
'Iceberg' => 'green',
137
+
'Butterhead' => 'green',
138
+
],
139
+
'carrots' => [
140
+
'Deep Purple Hybrid' => 'purple',
141
+
'Imperator' => 'orange',
142
+
],
143
+
'cucumber' => [
144
+
'Kirby' => 'green',
145
+
'Gherkin' => 'green',
146
+
],
147
+
];
148
+

149
+
array_unshift($foods, $vegetables);
150
+
var_dump($foods);
151
+
]]>
152
+
</programlisting>
153
+
&example.outputs;
154
+
<screen role="php">
155
+
<![CDATA[
156
+
array(3) {
157
+
[0] =>
158
+
array(3) {
159
+
'lettuce' =>
160
+
array(2) {
161
+
'Iceberg' =>
162
+
string(5) "green"
163
+
'Butterhead' =>
164
+
string(5) "green"
165
+
}
166
+
'carrots' =>
167
+
array(2) {
168
+
'Deep Purple Hybrid' =>
169
+
string(6) "purple"
170
+
'Imperator' =>
171
+
string(6) "orange"
172
+
}
173
+
'cucumber' =>
174
+
array(2) {
175
+
'Kirby' =>
176
+
string(5) "green"
177
+
'Gherkin' =>
178
+
string(5) "green"
179
+
}
180
+
}
181
+
'apples' =>
182
+
array(2) {
183
+
'McIntosh' =>
184
+
string(3) "red"
185
+
'Granny Smith' =>
186
+
string(5) "green"
187
+
}
188
+
'oranges' =>
189
+
array(2) {
190
+
'Navel' =>
191
+
string(6) "orange"
192
+
'Valencia' =>
193
+
string(6) "orange"
194
+
}
195
+
}
77
196
]]>
78
197
</screen>
79
198
</example>
...
...
@@ -83,6 +202,7 @@ Array
83
202
&reftitle.seealso;
84
203
<para>
85
204
<simplelist>
205
+
<member><function>array_merge</function></member>
86
206
<member><function>array_shift</function></member>
87
207
<member><function>array_push</function></member>
88
208
<member><function>array_pop</function></member>
89
209