Re: Associative Arrays
| From: | Robert Cummings | Date: | Fri, 20 Jun 2008 02:36:34 +0000 |
| Subject: | Re: Associative Arrays | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-275662@lists.php.net to get a copy of this message | ||
On Fri, 2008-06-20 at 11:19 +1000, Chris wrote:
> Paul Novitski wrote:
> > At 6/19/2008 05:55 PM, VamVan wrote:
> >> How to create an associative array of this kind in PHP?
> >>
> >> return array(
> >> 12345 => array(
> >> 'mail' => 'asdf@asdf.com',
> >> 'companyName' => 'Asdf Inc.',
> >> ),
> >> 54321 => array(
> >> 'mail' => 'asdf@asdf.net',
> >> 'companyName' => 'Asdfu Corp.',
> >> ),
> >> );
> >
> >
> > This is the right PHP syntax, except that you've got an extraneous comma
> > before the closing parenthesis of each array that's going to throw a
> > parse error.
>
> Actually that's allowed (and by design too) :)
Yep, it's there to primarily simplify generated PHP code. Additionally,
it sure makes commenting out chunks simple since you don't need to
comment out the preceding comma if commenting out the last entry.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP