0

For my banner/slider I change the content with a if elseif statement to load specific images and links. The amount of slider images are variable. I use 3 links separate from the images and 1 background image.

This is my code now: (2 time change examples)

if($epochTime > 1427641200) { // zo 29 maart

// slider images
img1
img2
img3
img4
img5
img6

// seperate links
link1
link2
link3

// background image
imgA

} elseif($epochTime > 1427040000) {  // zo 22 maart

// slider images
img3
img4
img7
img8

// seperate links
link2
link4
link5

// background image
imgB

}

Well, when I want to code several weeks forwards with different images, links and background, I have to copy/paste a lot of the same code again and again and adjust the images, links and background for the ones that week.

I like to simplefy this and thought about a (week) array containing the necessary data and parse them with some foreach code.

And here it stops for me :-(, I don't know how to set it up. Please help or advise. Thanks.

2
  • 1
    $aArray = array(); $aArray[] = 'item'; foreach ($aArray AS $key => value) { } Commented Mar 24, 2015 at 20:37
  • I know the formulation of 'foreach' (php sites) but the question is how to parse the multiple and seperate data along with it. Commented Mar 25, 2015 at 8:41

1 Answer 1

1

Well, I figured it out with a little help:

$epochTime = date("U");

$Data = array( // newest add at top here
    array(1427641200, array("img3","img4","img7","img8"), "link2", "link4", "link5", "imgB"), // 29 maart
    array(1427040000, array("img1","img2","img3","img4","img5","img6"), "link1", "link2", "link3", "imgA") // 22 maart
);

foreach ($Data as $Value) {

    if($epochTime > $Value[0]) {

        echo $Value[0]."<br>";
        foreach ($Value[1] as $ValueImgs) { echo $ValueImgs."<br>"; }
        echo $Value[2]."<br>".$Value[3]."<br>".$Value[4]."<br>";
        echo $Value[5];

    }
    break;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.