reference/array/functions/list.xml
43ac336818cb3a18011d9b6ba91514f3332eb46d
...
...
@@ -14,8 +14,10 @@
14
14
</methodsynopsis>
15
15
<para>
16
16
Like <function>array</function>, this is not really a function,
17
-
but a language construct. <function>list</function> is used to
17
+
but a language construct. <function>list</function> is used to
18
18
assign a list of variables in one operation.
19
+
Strings can not be unpacked and <function>list</function> expressions
20
+
can not be completely empty.
19
21
</para>
20
22
<note>
21
23
<para>
...
...
@@ -23,24 +25,6 @@
23
25
the numerical indices start at 0.
24
26
</para>
25
27
</note>
26
-
<warning>
27
-
<para>
28
-
In PHP 5, <function>list</function> assigns the values starting with the
29
-
right-most parameter. In PHP 7, <function>list</function> starts with the
30
-
left-most parameter.
31
-
</para>
32
-
<para>
33
-
If you are using plain variables, you don't have to worry about this. But
34
-
if you are using arrays with indices you usually expect the order of the
35
-
indices in the array the same you wrote in the <function>list</function>
36
-
from left to right, which is not the case in PHP 5, as it's assigned in the
37
-
reverse order.
38
-
</para>
39
-
<para>
40
-
Generally speaking, it is advisable to avoid relying on a specific order
41
-
of operation, as this may change again in the future.
42
-
</para>
43
-
</warning>
44
28
</refsect1>
45
29
<refsect1 role="parameters">
46
30
&reftitle.parameters;
...
...
@@ -98,26 +82,6 @@
98
82
enables destructuring of arrays with non-integer or non-sequential keys.
99
83
</entry>
100
84
</row>
101
-
<row>
102
-
<entry>7.0.0</entry>
103
-
<entry>
104
-
The order that the assignment operations are performed in has
105
-
changed.
106
-
</entry>
107
-
</row>
108
-
<row>
109
-
<entry>7.0.0</entry>
110
-
<entry>
111
-
<function>list</function> expressions can no longer be completely
112
-
empty.
113
-
</entry>
114
-
</row>
115
-
<row>
116
-
<entry>7.0.0</entry>
117
-
<entry>
118
-
Strings can no longer be unpacked.
119
-
</entry>
120
-
</row>
121
85
</tbody>
122
86
</tgroup>
123
87
</informaltable>
...
...
@@ -159,24 +123,12 @@ var_dump($bar); // NULL
159
123
<title>An example use of <function>list</function></title>
160
124
<programlisting role="php">
161
125
<![CDATA[
162
-
<table>
163
-
<tr>
164
-
<th>Employee name</th>
165
-
<th>Salary</th>
166
-
</tr>
167
-

168
126
<?php
169
-
$result = $pdo->query("SELECT id, name, salary FROM employees");
170
-
while (list($id, $name, $salary) = $result->fetch(PDO::FETCH_NUM)) {
171
-
echo " <tr>\n" .
172
-
" <td><a href=\"info.php?id=$id\">$name</a></td>\n" .
173
-
" <td>$salary</td>\n" .
174
-
" </tr>\n";
127
+
$result = $pdo->query("SELECT id, name FROM employees");
128
+
while (list($id, $name) = $result->fetch(PDO::FETCH_NUM)) {
129
+
echo "id: $id, name: $name\n";
175
130
}
176
-

177
131
?>
178
-

179
-
</table>
180
132
]]>
181
133
</programlisting>
182
134
</example>
...
...
@@ -206,54 +158,6 @@ int(3)
206
158
</para>
207
159
<para>
208
160
<example>
209
-
<title>Using <function>list</function> with array indices</title>
210
-
<programlisting role="php">
211
-
<![CDATA[
212
-
<?php
213
-

214
-
$info = array('coffee', 'brown', 'caffeine');
215
-

216
-
list($a[0], $a[1], $a[2]) = $info;
217
-

218
-
var_dump($a);
219
-

220
-
?>
221
-
]]>
222
-
</programlisting>
223
-
<para>
224
-
Gives the following output (note the order of the elements compared in
225
-
which order they were written in the <function>list</function> syntax):
226
-
</para>
227
-
&example.outputs.7;
228
-
<screen>
229
-
<![CDATA[
230
-
array(3) {
231
-
[0]=>
232
-
string(6) "coffee"
233
-
[1]=>
234
-
string(5) "brown"
235
-
[2]=>
236
-
string(8) "caffeine"
237
-
}
238
-
]]>
239
-
</screen>
240
-
&example.outputs.5;
241
-
<screen>
242
-
<![CDATA[
243
-
array(3) {
244
-
[2]=>
245
-
string(8) "caffeine"
246
-
[1]=>
247
-
string(5) "brown"
248
-
[0]=>
249
-
string(6) "coffee"
250
-
}
251
-
]]>
252
-
</screen>
253
-
</example>
254
-
</para>
255
-
<para>
256
-
<example>
257
161
<title><function>list</function> and order of index definitions</title>
258
162
<simpara>
259
163
The order in which the indices of the array to be consumed by
260
164