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

PHP的 foreach each list

不言
不言Original
2018-04-26 09:54:47987browse

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;);

}



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);



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));



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);
?>
*/



The above is the detailed content of PHP的 foreach each list. 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