reference/array/functions/array-unshift.xml
caf779183ee9860b48c74c8994fb944039b6b56f
...
...
@@ -10,7 +10,7 @@
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 choice="opt"><type>mixed</type><parameter>...</parameter></methodparam>
13
+
<methodparam rep="repeat"><type>mixed</type><parameter>values</parameter></methodparam>
14
14
</methodsynopsis>
15
15
<para>
16
16
<function>array_unshift</function> prepends passed elements to the front
...
...
@@ -19,6 +19,7 @@
19
19
order. All numerical array keys will be modified to start counting from
20
20
zero while literal keys won't be changed.
21
21
</para>
22
+
&note.reset-index;
22
23
</refsect1>
23
24
<refsect1 role="parameters">
24
25
&reftitle.parameters;
...
...
@@ -33,7 +34,7 @@
33
34
</listitem>
34
35
</varlistentry>
35
36
<varlistentry>
36
-
<term><parameter>...</parameter></term>
37
+
<term><parameter>values</parameter></term>
37
38
<listitem>
38
39
<para>
39
40
The values to prepend.
...
...
@@ -83,22 +84,115 @@
83
84
<programlisting role="php">
84
85
<![CDATA[
85
86
<?php
86
-
$queue = array("orange", "banana");
87
+
$queue = [
88
+
"orange",
89
+
"banana"
90
+
];
91
+

87
92
array_unshift($queue, "apple", "raspberry");
88
-
print_r($queue);
93
+
var_dump($queue);
89
94
?>
90
95
]]>
91
96
</programlisting>
92
97
&example.outputs;
93
98
<screen role="php">
94
99
<![CDATA[
95
-
Array
96
-
(
97
-
[0] => apple
98
-
[1] => raspberry
99
-
[2] => orange
100
-
[3] => banana
101
-
)
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
+
}
102
196
]]>
103
197
</screen>
104
198
</example>
...
...
@@ -108,6 +202,7 @@ Array
108
202
&reftitle.seealso;
109
203
<para>
110
204
<simplelist>
205
+
<member><function>array_merge</function></member>
111
206
<member><function>array_shift</function></member>
112
207
<member><function>array_push</function></member>
113
208
<member><function>array_pop</function></member>
114
209