至于还有没有其他的语法结构,hy369也没有特别去深究这个,所以不甚清楚,以后注意到再说吧。
list的作用是用数组为一组变量赋值。其语法为:
list(var1,var2...)
通过list可以很方便地将数组中的值赋予指定的变量。这里给出两个例子:
<?php$a=array("a"=>"dog","b"=>"cat","c"=>"horse"); print_r($a);
输出结果为:
array ( [a] => dog [b] => cat [c] => horse )
<?php$my_array = array("dog","cat","horse"); list($a, , $c) = $my_array; echo "here i only use the $a and $c variables.";
here i only use the dog and horse variables.
仔细注意一下第二个例子。hy369以前就为了获得非第一个数组的值,写过类似list($a,$b,$c) = $array的代码,然后输出我仅仅需要的$c的值。当时还不知道可以直接写成list(,,$c)=$arra就可以了(注意逗号)。现在想来,还是略微有些汗颜啊。
以上就是笔记012 php中的list语言结构的内容。
