@@ -414,9 +414,17 @@ isset($v1, $v2, $v3); // results in FALSE
414414 list ( <i >list-expression-list<sub >opt</sub ></i > )
415415
416416 <i >list-expression-list:</i >
417+ <i >unkeyed-list-expression-list</i >
418+ <i >keyed-list-expression-list</i > ,<sub >opt</sub >
419+
420+ <i >unkeyed-list-expression-list:</i >
417421 <i >list-or-variable</i >
418422 ,
419- <i >list-expression-list</i > , <i >list-or-variable<sub >opt</sub ></i >
423+ <i >unkeyed-list-expression-list</i > , <i >list-or-variable<sub >opt</sub ></ii >
424+
425+ <i >keyed-list-expression-list:</i >
426+ <i >expression</i > => <i >list-or-variable</i >
427+ <i >keyed-list-expression-list</i > , <i >expression</i > => <i >list-or-variable</i >
420428
421429 <i >list-or-variable:</i >
422430 <i >list-intrinsic</i >
@@ -446,7 +454,8 @@ target variables. On success, it returns a copy of the source array. If the
446454source array is not an array or object implementing ` ArrayAccess ` no
447455assignments are performed and the return value is ` NULL ` .
448456
449- All elements in the source array having keys of type ` string ` are ignored.
457+ For * unkeyed-list-expression-list* , all elements in the source array having
458+ keys of type ` string ` are ignored.
450459The element having an ` int ` key of 0 is assigned to the first target
451460variable, the element having an ` int ` key of 1 is assigned to the second
452461target variable, and so on, until all target variables have been
@@ -455,6 +464,15 @@ fewer source array elements having int keys than there are target
455464variables, the unassigned target variables are set to ` NULL ` and
456465a non-fatal error is produced.
457466
467+ For * keyed-list-expression-list* , each key-variable pair is handled in turn,
468+ with the key and variable being separated by the ` => ` symbol.
469+ The element having the first key, with the key having been converted using the
470+ same rules as the [ subscript operator] ( 10-expressions.md#subscript-operator ) ,
471+ is assigned to the frst target variable. This process is repeated for the
472+ second ` => ` pair, if any, and so on. Any other array elements are ignored.
473+ If there is no array element with a given key, the unassigned target variable
474+ is set to ` NULL ` and a non-fatal error is produced.
475+
458476The assignments must occur in this order.
459477
460478Any target variable may be a list, in which case, the corresponding
@@ -481,6 +499,24 @@ list($arr[1], $arr[0]) = [0, 1];
481499 // $arr is [1 => 0, 0 => 1], in this order
482500list($arr2[], $arr2[]) = [0, 1];
483501 // $arr2 is [0, 1]
502+
503+ list("one" => $one, "two" => $two) = ["one" => 1, "two" => 2];
504+ // $one is 1, $two is 2
505+ list(
506+ "one" => $one,
507+ "two" => $two,
508+ ) = [
509+ "one" => 1,
510+ "two" => 2,
511+ ];
512+ // $one is 1, $two is 2
513+ list(list("x" => $x1, "y" => $y1), list("x" => $x2, "y" => $y2)) = [
514+ ["x" => 1, "y" => 2],
515+ ["x" => 3, "y" => 4]
516+ ];
517+ // $x1 is 1, $y1 is 2, $x2 is 3, $y2 is 4
518+ list(0 => list($x1, $x2), 1 => list($x2, $y2)) = [[1, 2], [3, 4]];
519+ // $x1 is 1, $y1 is 2, $x2 is 3, $y2 is 4
484520```
485521
486522####print
0 commit comments