这种判断必须得保证后台数据的键值为数字 ,反正要能跟数字计算的数据才行
ts2.php
<?php $array = array('0'=>'a1','1'=>'b1','2'=>'c1','3'=>'d1','4'=>'e1','5'=>'f1');//print_r($array) ?>
ts3.php
<html > <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <script src="js/jquery-2.1.1.min.js"></script> <style type="text/css"> .q{color: red} .w{color: blue} .e{color: black} </style> <body> <?php include 'ts2.php'; ?> <ul> <?php foreach ($array as $k => $v) { ?>
<?php if(($k+1)%3==1){ ?> <li class="q"><?php echo $k;?></li> <?php } ?> <?php if(($k+1)%3==2){?> <li class="w"><?php echo $k;?></li> <?php } ?> <?php if(($k+1)%3==0){?> <li class="e"><?php echo $k;?></li> <?php } ?> <?php } ?> </ul> <!-- <ul> <li class="q"></li> <li class="w"></li> <li class="e"></li> <li class="q"></li> <li class="w"></li> <li class="e"></li> </ul> --> </body> </html>
|
请发表评论