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

WBOY
Libérer: 2016-06-13 13:39:09
original
780 Les gens l'ont consulté

看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>
Copier après la connexion
HTML code
Warning
list() 从最右边一个参数开始赋值。如果你用单纯的变量,不用担心这一点。但是如果你用了具有索引的数组,通常你期望得到的结果和在 list() 中写的一样是从左到右的,但实际上不是。是以相反顺序赋值的。 <div class="clear">
                 
              
              
        
            </div>
Copier après la connexion
Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!