Definition
The list() function is used to assign values to a list of variables in one operation.
Syntax
list(var1, var2, ...)
Parameters
Parameter | Description |
---|---|
var1 |
Required. The first variable to assign a value to. |
var2... |
Optional. More variables to assign values to. |
Example
<?php
// Example 1
$cities = array("New York", "Berlin", "Tokyo");
list($usa, $de, $jpn) = $cities;
echo "The capital of Germany is $de.";
echo "<br>";
// Example 2
$cities = array("New York", "Berlin", "Tokyo");
list( , $de, ) = $cities;
echo "The capital of Germany is $de.";
echo "<br>";