PHP list() Function

The list() function is used to assign values to a list of variables. Like array(), this is not really a function, but a language construct. list() is used to assign a list of variables in one operation.

Note: This function only works on numerical arrays.

Parameter Description
var1 Required. The first variable to assign a value to
var2,… Optional. More variables to assign values to

Syntax

list(var1,var2...)

Example

$my_array = array("Cooper","Samuel","James");
list($a, $b, $c) = $my_array;
echo "$a,$b, $c.";

Output

Cooper,Samuel, James.

Leave a Reply

Your email address will not be published. Required fields are marked *