Set two classes from array

Posted by Thomas on Stack Overflow See other posts from Stack Overflow or by Thomas
Published on 2010-06-07T09:08:21Z Indexed on 2010/06/07 9:12 UTC
Read the original article Hit count: 272

Filed under:
|

I want to change the classes on every third output from a query:

    <?php
$style_classes = array('box','box','box no_right_margin');
$style_index = 0;
?>

I set this on the div:

<div <?php $k = $style_index%4; echo "class=$style_classes[$k]"; $style_index++; ?>>

On the third div I want the class to look like this:

<div class="box no_right_margin">

Right now it looks like:

 <div class="box" no_right_margin>

© Stack Overflow or respective owner

Related posts about php

Related posts about Wordpress