List($array)是用来快速把数组中的元素赋给一些变量。使用时要注意,$array必须为一个索引数组,并且索引值从0开始

<?php
header("Content-type: text/html; charset=utf-8");
//list_array_3.php
$my_array = array();//("Dog","Cat","Horse");
$my_array['a']="Dog";
$my_array['b']="Cat";
$my_array['c']="Horse";

list($a, $b, $c) = $my_array;
echo "I have several animals, a $a, a $b and a $c.";
?>

 

 

 

 

( ! ) Notice: Undefined offset: 2 in D:\workspace\php\hellophp\list_array_3.php on line 9
Call Stack
#TimeMemoryFunctionLocation
1 0.0020 147088 {main}( ) ..\list_array_3.php:0

 

( ! ) Notice: Undefined offset: 1 in D:\workspace\php\hellophp\list_array_3.php on line 9
Call Stack
#TimeMemoryFunctionLocation
1 0.0020 147088 {main}( ) ..\list_array_3.php:0

 

( ! ) Notice: Undefined offset: 0 in D:\workspace\php\hellophp\list_array_3.php on line 9
Call Stack
#TimeMemoryFunctionLocation
1 0.0020 147088 {main}( ) ..\list_array_3.php:0

I have several animals, a , a and a .

posted @ 2017-11-23 09:58  sky20080101  阅读(109)  评论(0)    收藏  举报