jaswinder_rana — 2012-09-21T11:30:29-04:00 — #1
Confusing? yes. and I am not sure how to work it out.
I have following scenario:
- 3 vendors in array (=>A,=>B,=>C)
Now I need to assign this to another array which is 5 long for each day of the week (excluding Sunday and Saturday).
So, lets say today is Wednesday then the output should be:
[Wed] => A
[Thu] => B
[Fri] => C
[Mon] => A
[Tue] => B
I can't figure out how to achieve this. I have no code to display as its just concept and am only thinking how to do it. Tried to write code and even tried to draw it out on paper but can't figure out an easier way to do it without having lots of if and for statements.
wonshikee — 2012-09-21T17:34:16-04:00 — #2
If the first array is always the same, you can use the index of the array to determine the DAY.
You can say M = 0 and F = 4.
Then use the modulus operator to cycle the 5 into 3
Example for Tues:
1 % 3 = 1, so the value of Tuesday is $array, which is B.
Example for Thursday:
3 % 3 = 0, so the value of Thursday is $array, which is A.
cups — 2012-09-21T17:59:39-04:00 — #3
Is it true to say that from today (Friday) I want to use each supplier in turn (A, B, C) ad infinitum?
Or could that change at some point, and that on another day I will switch and suddenly have only two, or have four, or five?
jaswinder_rana — 2012-09-22T19:21:50-04:00 — #4
First array is not same. It can change
and yes, that array can change as we add/edit vendors. That's why the problem. Have to go to 5 days in the array and select 5 vendors (first one repeating if less than 5).
cups — 2012-09-23T06:11:10-04:00 — #5
How many weeks worth of matches do you have to generate?
How will you store the fact that the last used supplier was say, B, in order to generate the new set of matches when the first array of suppliers has to be regenerated? Is this in a text file, database?
jaswinder_rana — 2012-10-01T08:39:27-04:00 — #6
Thanks for all the replies.
It was to be for 5 days only. Now I say was, because the idea has been changed on how to take that approach so this is not needed anymore.