Scrolling array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Crew
Forum Newbie
Posts: 16
Joined: Fri Jul 15, 2005 4:05 am

Scrolling array

Post by Crew »

Code: Select all

function WeekGen($week,$array_size,$array,$index,$ud)
{
    $array_count = $index+$week;
    if($array_count>$array_size) {
        $array_count = $array_count - $array_size;
    }
    $weekgen = $array[$array_count];
    return $weekgen;
}
Hi

Using the above code I have an array that loops through itself like:

Code: Select all

Week 1
1
2
3
4

Week 2
4
1
2
3

Week 3
3
4
1
2
Now what I'm trying to do is get it so the weeks are as follows

Code: Select all

Week 1
1 4
2 3

Week 2
4 3
1 2

Week 3
3 2
4 1
And as simple as this sounds I really am struggling to get it to display in anything readable. Its frustrating :)

So does anyone have any hints or tips? And yes its a football league creator I'm making for a local league.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

Could you be a little more specific in terms of what the functions variables are used for?

Such as what is $index, $array_size etc. :)

Also, when you display the data, I know you have displayed the layout, but how would the layout be presented? Like that or in HTML Tables or divs/spans?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

I imagine you're output code looks similar to this:

Code: Select all

foreach($weeks as $curr_week)
{
   foreach($curr_week as $day)
   {
      echo $day."<br />";
   }
   echo "<br />";
}
If you want to put columns in, change it like this:

Code: Select all

foreach($weeks as $curr_week)
{
   $column = 1;
   foreach($curr_week as $day)
   {
      echo $day;
      if($column%2 == 0)
      {
         echo "<br />";
      }
      ++$column;
   }
   echo "<br />";
}
That will dump a <br /> every 2 items.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply