My code is like this
foreach($array as $key => $value) {
"<div class="myclass"><a href=$key>$value</a></div>"
}
here i want class to repeat two values like
<div class="class1">
<a href='link1'>text1</a>
</div>
<div class="class2">
<a href='link2'>text2</a>
</div>
<div class="class1">
<a href='link3'>text3</a>
</div>
<div class="class2">
<a href='link4'>text4</a>
</div>
I think you can understand what i want from the above code. I can’t think of a way to do this. I don’t want to use the same class on all div. Anybody have any idea?
Thanks
I’d keep a count variables that keeps track of the row number. You could use the array’s key but that would assume that they’re numeric, sequential and starting at 0. As you iterate through each row, you increment the counter by one and check whether it’s odd or even.
Here’s a short example: