Page 1 of 1

string array - strange behaviour

Posted: Sat Aug 09, 2008 3:24 am
by polarke
I am creating this 'message of the day' topic. Therefore I fill in first a string array.

$motd[1+1*31]="This is January 1st";
$motd[2+1*31]="This is January 2nd";
...
$motd[31+12*31]="lalala";

Then I select the message to write out using date(). I have now the problem, that starting from 5th of August, the strings for dates after are empty (they have however an initialisation line)

What can cause this and what can avoid this?

NB: I split up the list of initialisations using an if then else on (date("m")<8) and this moved forward the point were strings were starting to be empty with 5 days or so.

Thanks for any help.

Re: string array - strange behaviour

Posted: Sat Aug 09, 2008 4:37 am
by filippo.toso
Why 1 + 1 * 31 is the 1st of January?

If you use date('z') as index, the 1st of January is 0, the 1st of February is 31, the 1st of March is 59 and so on.

Re: string array - strange behaviour

Posted: Sat Aug 09, 2008 6:49 am
by polarke
Yes, thats true, but it need to be correct for years with 28 days in February.
AND: The messages are coupled, so we need to deduct fast the real date from the nr.

But that's not the point, the point is: the string array is not working.

Re: string array - strange behaviour

Posted: Sat Aug 09, 2008 8:04 am
by filippo.toso
polarke wrote:Yes, thats true, but it need to be correct for years with 28 days in February.
That's easy. Just create the array for leap year and then use the http://www.php.net/array_splice to remove the 29 February when you need to use the array against a non leap year.
polarke wrote:The messages are coupled, so we need to deduct fast the real date from the nr.
I' sorry, but I can't understand what you mean. With the index of the message you can easily get the unix timestamp of the day it refers to.
polarke wrote:But that's not the point, the point is: the string array is not working.
What you mean with "the string array is not working". If you execute print_r($motd) does it contains all the required values?
How do you access the values and get the wrong result (the initialisation line)?

Re: string array - strange behaviour

Posted: Sat Aug 09, 2008 12:18 pm
by polarke
If you execute print_r($motd) does it contains all the required values?
No, the strings are empty from a specific index.
The print_r() prints indexes 32 to 38, then 31 (!- not in order, and 31 should be empty),
then continueing with 41, 42 etc...