Home > Backend Development > PHP Tutorial > php foreach嵌套循环 输出键值,该怎么处理

php foreach嵌套循环 输出键值,该怎么处理

WBOY
Release: 2016-06-13 13:18:24
Original
970 people have browsed it

php foreach嵌套循环 输出键值
foreach($list1 as $k=>$v){
  $list2 = $this->getList($v);
  foreach($list2 as $ks=>$vs){
  $a = $ks+1;
  }
}
求$a的值 像我这样循环,每循环一次 $ks就从0重新开始累加了

我想得到$a的值从1开始每次都加1 列如1 2 3 4 5 6 7 8 9 10 11。。。。。


------解决方案--------------------
$a = 0;
foreach($list1 as $k=>$v){
$list2 = $this->getList($v);
foreach($list2 as $ks=>$vs){
$a++;
}
}

这个意思?
------解决方案--------------------

PHP code

$a=0;
foreach($list1 as $k=>$v){
  $list2 = $this->getList($v);
  foreach($list2 as $ks=>$vs){
  echo $a++."<br>";
  }
} <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