On Tue, Nov 18, 2008 at 2:58 PM, Ashley Sheridan
<[EMAIL PROTECTED]> wrote:
> It just flew in the face of all I knew at the time to have a
> non-associative system-generated array (by that I mean one whos keys are
> integars and not string keys) that doesn't start at 0. No other arrays
> defined in Javascript that I'm aware of behave like this, not even the
> DOM ones.
>
>
> Ash
> www.ashleysheridan.co.uk

That's what I'm talking about. Those functions like javascript's
getMonth() return an int that is one less than the month number. My
assumption is that people who defined the language made it this way so
that you can write code that uses non-associative, zero-based arrays
to decode the month number to a string:

var month_names['en'] = new Array('January', 'February', 'March',
'April', 'May', 'June', 'July', 'August', 'September', 'October',
'November', 'December');
var myDate = new Date();
var x = month_names['en'][myDate.getMonth()];


If getMonth() wasn't zero-based, you'd either have to include an empty
element in the 0th position of at the beginning of the array, use an
associative array, or that last line would have to be changed:

var x = month_name['en'][myDate.getMonth() - 1]'

Andrew

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to