PHP Arrays

Associate
Joined
18 Jul 2009
Posts
678
Location
UK
Hello, I am writing a calendar using PHP, but I am having difficulty manipulating or even using arrays.

Why doesn't this work?
Code:
$remainingDays = ($monthStart + $daysInMonth[$month - 1]) % 7;

The array is defined as

Code:
$daysInMonth = array(31, 28, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30);

I have exactly the same script written in javascript and it works, but I am just not sure on how to use arrays in PHP.

Thanks in advance.
 
Perfectly valid assuming that the variables $month and $monthStart are given a suitable value (you did not show where they were initialised or assigned).

Given the following state:
Code:
$month = 4;
$monthStart = 1;

$daysInMonth should have the value 3.
 
$monthstart is the day a month starts on, so it is between 0 and 6.

$month is the month, i.e. 4 = April, and $daysInMonth is the amount of days in the month i.e. 30, 31 etc.

We were asked to create a calendar for 2010 only, so I made this... but I'm starting to think it may be easier to use the month() function and use that...
 
Back
Top Bottom