Jump to content

Alternate markup in an array (solved)


mel47
 Share

Recommended Posts

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...