Home  >  Article  >  Backend Development  >  PHPlist, each function traverses arrays (source code attached)

PHPlist, each function traverses arrays (source code attached)

慕斯
慕斯Original
2021-05-20 11:59:231515browse

The list function in PHP traverses the array?PHPlist, each function traverses arrays (source code attached)

How to use the list function: list(mixed$ variable 1[, mixed $variablen]), has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

1. How to use the list function list (mixed$ variable 1[, mixed $ variable n]), the code is as follows

<?php
list($one,$two,$three)=array(&#39;张三&#39;,&#39;李四&#39;,&#39;王五&#39;);
//再次声明:单引号不解释变量,所以输出的是字符串$one//
echo $one;
echo &#39;$two...&#39;.$two.&#39;<br/>&#39;;
echo &#39;$three...&#39;.$three.&#39;<br/>&#39;;
?>

It can be seen that the function of list is: the corresponding variable with subscript 0 in the cited array is 1, the corresponding variable with subscript 1 is 2, and so on.

Conclusion:

1: Assign Zhang San with subscript 0 to $one

2: Assign Li with subscript 1 Four is assigned to $two

3: Zhang San with subscript 2 is assigned to $three

. Finally, we get that the function of list is from left to right, --corresponding to the index array Subscript starting from 0;

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of PHPlist, each function traverses arrays (source code attached). For more information, please follow other related articles on the PHP Chinese website!

Statement:
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