php - Changing class every in a foreach loop every 2 times -
I'm trying to change every 2x tr square in my loop, but I'm not sure of How can I calculate twice so far I have:
foreach (array_chunk $$ user, 2, true) as $ array) {} I divided the $ user array of two, but where can I go from here? I am trying to output:
& lt; Tr class = "m0" & gt; & Lt; Td> & Lt; A href = "id.php? Id = 1" & gt; Bob & lt; / A & gt; & Lt; / Td> & Lt; Td> & Lt; A href = "profile.php? Id = 2" & gt; Bob's cousin & lt; / A & gt; & Lt; / Td> & Lt; / TR & gt; & Lt; Tr class = "m1" & gt; & Lt; Td> & Lt; A href = "profile.php? Id = 3" & gt; Bob's mother & lt; / A & gt; & Lt; / Td> & Lt; Td> & Lt; A href = "profile.php? Id = 4" & gt; Bob's father & lt; / A & gt; & Lt; / Td> & Lt; / TR & gt;
Why do you need alternate names? If this is just for style then you can simply use the CSS "nth-child"
Example:
CSS
Table # Result tr: nth-child (even) {background color: red; } Table # results tr: nth-child (weird) {background-color: blue; } HTML
& lt; Table ID = "Result" & gt; & Lt; TR & gt; & Lt; TD & gt; Foo & lt; / TD & gt; & Lt; / TR & gt; & Lt; TR & gt; & Lt; TD & gt; Bar & lt; / TD & gt; & Lt; / TR & gt; & Lt; / Table & gt; Object:
Comments
Post a Comment