Jump to content

[SOLVED] Problem with Array.


photodow

Recommended Posts

Alright, I am trying to include a file every year from my array. My only problem is, is that I have only three files to cycle through.

 

Here is my script:

 

--------------------

 

<?php

 

$year = date('y');

 

$file_index = $year - 5;

$files = array("classbaby.html","classhigh.html","class456.html");

 

$week_file = $files[$file_index];

 

include $week_file;

 

?>

 

--------------------

 

Now this year should be displaying the file called "class456.html", and I'm using the - 5 to get that. Well this is all working wonderfully until i replace - 5 with - 4 to see what happens on my fourth year of this script. All I get is an error saying the file doesn't exist. Do any of you know how I can loop it around to where ever four years it starts over?

 

I assume it has to do with the loop command, but I haven't been able to figure it out yet.

 

Thanks for any help you can give!

 

Link to comment
https://forums.phpfreaks.com/topic/41010-solved-problem-with-array/
Share on other sites

Yes I think I understand that part of it.  But what I'm trying to do is get it to where on the fourth year of this script running it starts over to where it displays "classbaby.html" and continues with the rest of the array.

 

Here is sort of what I want it to do:

 

Display

 

Year one: classbaby.html

Year two: classhigh.html

year three:  class456.html

year four:  classbaby.html

year five:  classhigh.html

year six:  class456.html

 

And so on, and so forth.

 

Does that make since?

 

You see I think I can write out those three about 100 times, and it would do what I want it to do, but when trying to re-edit the script or going in to add some other file that would be a pain in the back.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.