PHP中余数、取余的妙用

前端之家收集整理的这篇文章主要介绍了PHP中余数、取余的妙用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<div class="jb51code">
<pre class="brush:PHP;">
<?php

$ary=array("name","egineer","sonny","tonny","pingk","apple","phone","clone","pink","colle");
foreach($ary as $key=>$value){
$key=$key+1;
if($key%2==1){echo '

  • ';}
    ?>
    <?php echo $key.":". $value;?>

    <?PHP
    if($key%2==0){echo '

  • ';}
    };
    ?>

    second_one

    PHP;"> $ary=array("name","colle");
    foreach($ary as $key=>$value){
    $key=$key;
    if($key%3==0){echo '
  • ';}
    ?>
    <span class="<?php echo($key%3); ?>span"><?php echo $key.":". $value;?>

    <?PHP
    if($key%3==2){echo '

  • ';}
    };
    ?>

    大家可以运行以后查看结果并分析其巧妙之处~

    猜你在找的PHP相关文章