reference/array/functions/array-unshift.xml
0987e913fcaed76897aeb239c6ed83d765a895e1
0987e913fcaed76897aeb239c6ed83d765a895e1
...
...
@@ -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
+
¬e.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,123 @@
58
84
<programlisting role="php">
59
85
<![CDATA[
60
86
<?php
61
-
$queue = array("orange", "banana");
87
+
88
+
$queue = [
89
+
"orange",
90
+
"banana"
91
+
];
92
+
62
93
array_unshift($queue, "apple", "raspberry");
63
-
print_r($queue);
94
+
95
+
var_dump($queue);
96
+
97
+
?>
98
+
]]>
99
+
</programlisting>
100
+
&example.outputs;
101
+
<screen role="php">
102
+
<![CDATA[
103
+
array(4) {
104
+
[0] =>
105
+
string(5) "apple"
106
+
[1] =>
107
+
string(9) "raspberry"
108
+
[2] =>
109
+
string(6) "orange"
110
+
[3] =>
111
+
string(6) "banana"
112
+
}
113
+
]]>
114
+
</screen>
115
+
</example>
116
+
</para>
117
+
<para>
118
+
<example>
119
+
<title>Usage with associative arrays</title>
120
+
<para>
121
+
If one associative array is prepended to another associative array,
122
+
the prepended array is numerically indexed into the former array.
123
+
</para>
124
+
<programlisting role="php">
125
+
<![CDATA[
126
+
<?php
127
+
128
+
$foods = [
129
+
'apples' => [
130
+
'McIntosh' => 'red',
131
+
'Granny Smith' => 'green',
132
+
],
133
+
'oranges' => [
134
+
'Navel' => 'orange',
135
+
'Valencia' => 'orange',
136
+
],
137
+
];
138
+
139
+
$vegetables = [
140
+
'lettuce' => [
141
+
'Iceberg' => 'green',
142
+
'Butterhead' => 'green',
143
+
],
144
+
'carrots' => [
145
+
'Deep Purple Hybrid' => 'purple',
146
+
'Imperator' => 'orange',
147
+
],
148
+
'cucumber' => [
149
+
'Kirby' => 'green',
150
+
'Gherkin' => 'green',
151
+
],
152
+
];
153
+
154
+
array_unshift($foods, $vegetables);
155
+
156
+
var_dump($foods);
157
+
64
158
?>
65
159
]]>
66
160
</programlisting>
67
161
&example.outputs;
68
162
<screen role="php">
69
163
<![CDATA[
70
-
Array
71
-
(
72
-
[0] => apple
73
-
[1] => raspberry
74
-
[2] => orange
75
-
[3] => banana
76
-
)
164
+
array(3) {
165
+
[0]=>
166
+
array(3) {
167
+
["lettuce"]=>
168
+
array(2) {
169
+
["Iceberg"]=>
170
+
string(5) "green"
171
+
["Butterhead"]=>
172
+
string(5) "green"
173
+
}
174
+
["carrots"]=>
175
+
array(2) {
176
+
["Deep Purple Hybrid"]=>
177
+
string(6) "purple"
178
+
["Imperator"]=>
179
+
string(6) "orange"
180
+
}
181
+
["cucumber"]=>
182
+
array(2) {
183
+
["Kirby"]=>
184
+
string(5) "green"
185
+
["Gherkin"]=>
186
+
string(5) "green"
187
+
}
188
+
}
189
+
["apples"]=>
190
+
array(2) {
191
+
["McIntosh"]=>
192
+
string(3) "red"
193
+
["Granny Smith"]=>
194
+
string(5) "green"
195
+
}
196
+
["oranges"]=>
197
+
array(2) {
198
+
["Navel"]=>
199
+
string(6) "orange"
200
+
["Valencia"]=>
201
+
string(6) "orange"
202
+
}
203
+
}
77
204
]]>
78
205
</screen>
79
206
</example>
...
...
@@ -83,6 +210,7 @@ Array
83
210
&reftitle.seealso;
84
211
<para>
85
212
<simplelist>
213
+
<member><function>array_merge</function></member>
86
214
<member><function>array_shift</function></member>
87
215
<member><function>array_push</function></member>
88
216
<member><function>array_pop</function></member>
89
217