Home > Backend Development > PHP Tutorial > PHP的 foreach each list

PHP的 foreach each list

不言
Release: 2023-03-24 20:06:01
Original
1027 people have browsed it

This article mainly introduces the foreach each list about PHP, which has a certain reference value. Now I share it with everyone. Friends in need can refer to it

<?php
 
/*foreach (函数名 as 地址下标 => 该下标对应的数值)
$arr = [&#39;a&#39;,&#39;b&#39;,&#39;c&#39;,&#39;d&#39;,&#39;e&#39;,&#39;f&#39;,&#39;g&#39;];
foreach( $arr as $key=>$val) {
var_dump($key.&#39;--------&#39;.$val.&#39;<br  />&#39;);

}
Copy after login



The use of list is similar to directly copying the value in the array to the variable of the list, and then outputting


  $arr = [&#39;a&#39;,&#39;b&#39;,&#39;c&#39;,&#39;d&#39;,&#39;e&#39;,&#39;f&#39;,&#39;g&#39;];

   list($a,$b,$c,$d,$e) = $arr;

   var_dump($a,$b,$c,$d,$e);
Copy after login



Each is equivalent It is used to read by row, but this is to read the data corresponding to the address one by one

  $arr = [&#39;abc&#39;,&#39;b&#39;,&#39;c&#39;,&#39;d&#39;,&#39;e&#39;,&#39;f&#39;,&#39;g&#39;];
  var_dump(each($arr));
    var_dump(each($arr));
  var_dump(each($arr));
    var_dump(each($arr));
  var_dump(each($arr));
Copy after login



This is a combination of list and each, similar to the use of foreach When the output address is the same as the corresponding value

 $arr = [&#39;abc&#39;,&#39;b&#39;,&#39;c&#39;,&#39;d&#39;,&#39;e&#39;,&#39;f&#39;,&#39;g&#39;];
list($key,$val) = each($arr);
var_dump($key,$val);
    list($key,$val) = each($arr);
var_dump($key,$val);
list($key,$val) = each($arr);
var_dump($key,$val);
list($key,$val) = each($arr);
var_dump($key,$val);
?>
*/
Copy after login



The above is the detailed content of PHP的 foreach each list. For more information, please follow other related articles on the PHP Chinese website!

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