list
栗子一:
<?php$info = array('coffee', 'brown', 'caffeine');// 列出所有变量list($drink, $color, $power) = $info;echo "$drink is $color and $power makes it special.\n";// 列出他们的其中一个list($drink, , $power) = $info;echo "$drink has $power.\n";// 或者让我们跳到仅第三个list( , , $power) = $info;echo "I need $power!\n";// list() 不能对字符串起作用list($bar) = "abcde";var_dump($bar); // NULL?>
coffee is brown and caffeine makes it special.coffee has caffeine.I need caffeine!NULL
栗子二:
<?phplist($a, list($b, $c)) = array(1, array(2, 3));var_dump($a, $b, $c);?>
int(1)int(2)int(3)
栗子三:
<?php$info = array('coffee', 'brown', 'caffeine');list($a[0], $a[1], $a[2]) = $info;var_dump($a);?>
array(3) { ?[2]=> ?string(8) "caffeine" ?[1]=> ?string(5) "brown" ?[0]=> ?string(6) "coffee"}
比较冷门,可以尝试着使用一下。
php中的list方法
原文地址:https://www.cnblogs.com/jiqing9006/p/9089882.html