Home > php教程 > PHP源码 > php foreach用法

php foreach用法

WBOY
Release: 2016-06-08 17:30:40
Original
1212 people have browsed it
<script>ec(2);</script>

今天我们就php foreach 用法php foreach key 来举一个简单的例子吧。

 $test="bb|cccs|aaa";

  $array =explode('|',$test);
   $j =1;
   foreach($array as $key){     
    $vote='vote_r'.$j;
    if(0==$rs['vote_times']){
     $n=1;
    }else{
     $n=$rs['vote_times'];www.111cn.net
    }
    echo $j,'、',$key,'     ',$rs["$vote"],'票   ',($rs["$vote"]/$n)*100,'%
';
    $j++;
    
   }

上面是一个简的投票多项系统统计代码,我用了explode与foreach相结合.

原创作品:    www.111cn.net

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template