Re: An array curiosity....

From: Date: Mon, 26 Jan 2004 18:08:22 +0000
Subject: Re: An array curiosity....
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-175791@lists.php.net to get a copy of this message
On Mon, 2004-01-26 at 09:57, joel boonstra wrote: > On Mon, Jan 26, 2004 at 08:50:51AM -0600, Jay Blanchard wrote: > > Out of curiosity, and because I have never noted this in other > > languages, why doesn't an 'open' comma at the end of an array throw any > > kind of error? Is it because the comma denotes another element in the > > array even if nothing is their? For example > > > > $arrBadInfo = array( > > 'stuff ', > > 'morstuff', > > ); > > > > does not throw an error - even syntactical - > > This is as a convenience to programmers. Often arrays have things added > or removed as you're coding -- not having to worry about removing a > trailing comma for an element that is now the last one, or adding one to > previous elements when adding items to the list is a small but useful > timesaver. > > Perl does this as well. I'm not sure which other languages do, but I > like it. C also supports it. Personally I leave a trailing comma for the exact reason mentioned above. Cheers, Rob. -- .------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------'

« previous php.general (#175791) next »