PHP » Arrays » list()

void list(mixed variable1 [, mixed variable2, ...])
The variable to be assigned the value of the first element of the array.
The variable to be assigned the value of the second element of the array.

Makes variable assignments based on an array.

The list() construct can be thought of as the opposite to the array() function. It assigns values to a number of variables based on the elements of an array. This is often useful in different kinds of data extraction.



$address = "Broadway, Knoxville, TN, USA";
list($road, $city, $state, $country) = split(", ", $address);
print "Road: $road<br>";
print "City: $city<br>";
print "State: $state<br>";
print "Country: $country<br>";

Road: Broadway
City: Knoxville
State: TN
Country: USA

Using the split() function, a comma separated address string is split into an array containing the address components. The list function is used on the resulting array to extract the address components and assign them to variables. Finally, the result is printed.

See Also: