This is one of those functions (though it’s actually a language construct) that’s easier to use than it is to explain. Basically you can assign values to a list of variables all at once.

It can function similar to extract()

$food = array('apple',
              'banana',
              'carrot');
 
list($one, $two, $three) = $food;
/*
Same as:
$one   = 'apple';
$two   = 'banana';
$three = 'carrot';
*/
 
list($one, , $two) = $food;
/*
Same as:
$one = 'apple';
$two = 'carrot';
*/
 
 
list($one, $two) = $food;
/*
Same as:
$one = 'apple';
$two = 'banana';
*/
 
list($only) = $one; // a
/*
Since $one contains 'apple', this is like
$only = $one[0];
which leaves $only containing the value 'a'
*/
 
list(, , , $only) = $one; // l
 
// does not work with strings which aren't in a variable
list($only) = 'apple'; // null

list() only works with numeric array keys. Any others will be ignored.

$food = array('apple',
              'q' => 'monkey',
              'banana',
              'carrot');
 
list($one, $two, $three) = $food;
/*
Same as:
$one   = 'apple';
$two   = 'banana';
$three = 'carrot';
*/

This is what makes it work with each() which returns an array with both numeric and associative keys.

$arr = array('a' => 'apple',
             'b' => 'banana',
             17  => 'carrot');
 
// remember that each() will return false after the last element which exits this loop
while( list($key, $value) = each($arr) ) {
  echo "$key - $value\n";
}
/*
a - apple
b - banana
17 - carrot
*/

One final note. list() assigns the values from right to left in your list of variables. This normally won’t affect you but consider the following examples.

In the first, our list is elements of an array. Since the right most element is assigned first, it will be first in a foreach loop for instance.

The second example uses the variable variables concept. I don’t recommend actually doing this, of course. It’s rather silly.

$food = array('apple',
              'banana',
              'carrot');
 
list($a[0], $a[1], $a[2]) = $food;
var_export($a);
/*
array (
  2 => 'carrot',
  1 => 'banana',
  0 => 'apple'
)
*/
 
$first_element = reset($a); // carrot
 
// a confusing - but valid - example using a variable variable
list($one, $$three, $three) = $food;
/*
Same as:
$one    = 'apple';
$carrot = 'banana';
$three  = 'carrot';
*/