list()只用于数字索引的数组,且假定数字索引从 0 开始。当数组不是数字数组而是关联数组时,如:
<?php
$my_array = array('a'=>'Dog','b'=>'Cat','c'=>'Horse');
list($a, $b, $c) = $my_array;
echo 'I have several animals, a '.$a.', a '.$b.' and a '.$c;
?>
结果将会报错
有个东西叫each
<?php
$my_array = array('a'=>'Dog','b'=>'Cat','c'=>'Horse');
list($a, $b, $c) = each($my_array);
echo 'I have several animals, a '.$a.', a '.$b.' and a '.$c;