Note: list() only works on numerical arrays and assumes the numerical indices start at 0.
$fruit = array('a' => 'apple','b' => 'banana','c' => 'cranberry');
list($a,$b,$c) = $fruit;
echo($a . $b . $c);
//这个$a,$b,$c是没有值的while(list($key,$val) = ($tmp=each($fruit)) )
{
    print_r($tmp);
    echo "{$key} => {$val}<br>";
}
//这里的each是返回$fruit当前指针的键/值的对应值
//每一次循环[$tmp]返回类似{[1] => apple  [value] => apple  [0] => a  [key] => a}
//而list只能得到数字索引,于是list($key,$val) = each($fruit)得到的是[1] => apple,[0] => a
//故[val] => apple,[key] => a
//【each:返回数组中当前的键/值对并将数组指针向前移动一步】//楼主是逗俺们玩的吧

解决方案 »

  1.   

    用了each根本就是两回事了。。去了解一下each的思想先。
      

  2.   

    each --  返回数组中当前的键/值对并将数组指针向前移动一步 
    想一下下面这段代码会输出什么?<?
    $arr = array('key' => 'value', 'foo' => 'bar');
    print_r(each($arr));
    ?>
    上面代码的输出为:
    Array ( [1] => value [value] => value [0] => key [key] => key ) 现在明白了吧!