Home > Backend Development > PHP Tutorial > 看PHP手册,有段话不太理解解决思路

看PHP手册,有段话不太理解解决思路

WBOY
Release: 2016-06-13 13:39:09
Original
808 people have browsed it

看PHP手册,有段话不太理解
在介绍list时候,给出了如下warning:

list() assigns the values starting with the right-most parameter. If you are using plain variables, you don't have to worry about this. But if you are using arrays with indices you usually expect the order of the indices in the array the same you wrote in the list() from left to right; which it isn't. It's assigned in the reverse order. 
我自己翻译不太明白,list有下标吗?list为什么从右到左赋值?什么情况是他所说的list下标和数组下标相反? 
我是新手,希望哪位高手予以解答,不胜感激!!!!

------解决方案--------------------
手册下面还有例子呢


$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"
}


看出问题了没、?如果没,这样子运行

$info = array('coffee', 'brown', 'caffeine');
list($a[], $a[], $a[]) = $info;
var_dump($a);
------解决方案--------------------
示例1

PHP code
list($a, $b, $c) = array(1, 2, 3);
print_r(array($a, $b, $c));
<br><font color="#e78608">------解决方案--------------------</font><br>你说的有中文注释吧!http://php.net/manual/zh/function.list.php<br>
Copy after login
HTML code
Warning
list() 从最右边一个参数开始赋值。如果你用单纯的变量,不用担心这一点。但是如果你用了具有索引的数组,通常你期望得到的结果和在 list() 中写的一样是从左到右的,但实际上不是。是以相反顺序赋值的。 <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template