list

PHP 4, PHP 5, PHP 7, PHP 8
list - Assign variables as if they were an array
Manual
Code Examples

list( mixed$var, [ ... mixed$vars] ): array

Like array, this is not really a function, but a language construct. list is used to assign a list of variables in one operation. Strings can not be unpacked and list expressions can not be completely empty.

Note:

Before PHP 7.1.0, list only worked on numerical arrays and assumes the numerical indices start at 0.

Parameters

var

A variable.

vars

Further variables.

Return Values

Returns the assigned array.

Changelog

Version Description
7.3.0 Support for reference assignments in array destructuring was added.
7.1.0 It is now possible to specify keys in list. This enables destructuring of arrays with non-integer or non-sequential keys.

Related Functions

Example of list

Show all examples for list

PHP Version: