How to output a value on every third result of a foreach statement in php?

前端 未结 11 1897
醉话见心
醉话见心 2021-01-04 13:37

I have a foreach statement in my app that echos a list of my database results:



        
11条回答
  •  温柔的废话
    2021-01-04 14:02

    What leaves your code mostly in tact would be

    ',(($i % 3) ? "result" : "result_every_third" ));
    echo $fp['project_name'];
    echo '
    '; $i++; } ?>

    But you may want to consider using a for or while construct around "each($featured_projects)" (see http://php.net/manual/en/function.each.php) which may result in neater code.

提交回复
热议问题