mel47 Posted October 29, 2020 Share Posted October 29, 2020 Hi, I need to print in alternation a different markup such as : Markup1 for item 1 Markup2 for item 2 Markup1 for item 3 Markup2 for item 4 I tried different versions since I was thinking having found solution on previous posts, but it didn't do as I want. Or it print a class odd-even in a div or print the same markups but reordering as item 1, 3, 5, 2, 4, 6. Thanks! Mel Link to comment Share on other sites More sharing options...
elabx Posted October 29, 2020 Share Posted October 29, 2020 The solutions pointed on those threads seem to point the right way to what you want to do, maybe if you could post some code? Link to comment Share on other sites More sharing options...
mel47 Posted October 29, 2020 Author Share Posted October 29, 2020 Yeah, sure. $odd = ''; $even = ''; foreach ($page->plus as $key => $projet) { if ($key % 2) { $even .= "some html code : A"; } else { $odd .= "some html code (not the same) : B"; } } $content .= $odd; $content .= $even; But I end up with B, B, B, A, A, A I want B, A, B, A, B, A. I'm close, but not exactly what I need. I understand why, but I don't where add $content. Do I need an other loop at the end? Or it shouldn't be a if/else? Thanks Link to comment Share on other sites More sharing options...
elabx Posted October 29, 2020 Share Posted October 29, 2020 $content = ""; foreach ($pages->plus as $key => $projet) { if ($key % 2) { $content .= "A"; } else { $content .= "B"; } } echo $content; Can you try this? 1 1 Link to comment Share on other sites More sharing options...
mel47 Posted October 29, 2020 Author Share Posted October 29, 2020 Wow! So simple. Thanks so much!! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now