# Array Question

- Thread: https://externals.io/message/10560
- Original archive: https://news-web.php.net/php.internals/10560
- Started by Jason Garber on 2004-06-17T08:03:36+00:00
- Messages: 10
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #10560 — Jason Garber — 2004-06-17T08:03:36+00:00

URL: https://externals.io/message/10560#10560

Hello,

In PHP4 and PHP5 the following syntax works fine (note the last comma):

array
(
     1 => 'bob',
     2 => 'sam',
);


Is being able to have a comma at the END of an array definition a supported 
feature, or an undocumented feature that should not be used?

Thanks,
Jason Garber


__________________________________________________________
Jason Garber
President & Chief Technology Officer
IonZoft, Inc.
814.742.8030 :: jason@ionzoft.com :: http://IonZoft.com
__________________________________________________________

---

## #10562 — Derick Rethans — 2004-06-17T08:33:39+00:00

URL: https://externals.io/message/10560#10562 · In reply to: #10560

> Hello,
>
> In PHP4 and PHP5 the following syntax works fine (note the last comma):
>
> array
> (
>      1 => 'bob',
>      2 => 'sam',
> );
>
>
> Is being able to have a comma at the END of an array definition a supported
> feature, or an undocumented feature that should not be used?

It's an undocumented feature AFAIK.

Derick

---

## #10563 — Antony Dovgal — 2004-06-17T08:43:15+00:00

URL: https://externals.io/message/10560#10563 · In reply to: #10562

On Thu, 17 Jun 2004 10:33:39 +0200 (CEST)
Derick Rethans <derick@php.net> wrote:

> 
> 
> > […]
> 
> It's an undocumented feature AFAIK.

There is user note about it here:
http://www.php.net/manual/en/function.array.php

-----
10-May-2003 03:53 
Similarly to a comment by stlawson at sbcglobal dot net on this page:
http://www.php.net/basic-syntax.instruction-separation

It is usually advisable to define your arrays like this:
$array = array(
     'foo',
     'bar',
);

Note the comma after the last element - this is perfectly legal.
Moreover, it's best to add that last comma so that when you add new
elements to the array, you don't have to worry about adding a comma
after what used to be the last element.

$array = array(
     'foo',
     'bar',
     'baz',
);
-----

But yes, perhaps it should be mentioned in the doc, that the comma at
the end is ok.

---
WBR,
Antony Dovgal aka tony2001
tony2001@phpclub.net || antony@dovgal.com

---

## #10569 — Adam Maccabee Trachtenberg — 2004-06-17T15:20:45+00:00

URL: https://externals.io/message/10560#10569 · In reply to: #10560

> Is being able to have a comma at the END of an array definition a supported
> feature, or an undocumented feature that should not be used?

If I remember correctly, Zeev or Andi specifically added it as a
result of a user request, so I'd say it's an undocumented feature.

-adam

-- 
adam@trachtenberg.com
author of o'reilly's php cookbook
avoid the holiday rush, buy your copy today!

---

## #10570 — Robert Cummings — 2004-06-17T17:00:38+00:00

URL: https://externals.io/message/10560#10570 · In reply to: #10569

> 
> 
> > […]
> 
> If I remember correctly, Zeev or Andi specifically added it as a
> result of a user request, so I'd say it's an undocumented feature.

At the end of the array definition or after the last defined array
entry? If the latter... good feature. Hope it's there to stay since it
makes cutting and pasting to arrays a lot easier and various other
automated array building tasks :)

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.          |
`------------------------------------------------------------'

---

## #10571 — Hartmut Holzgraefe — 2004-06-17T17:46:46+00:00

URL: https://externals.io/message/10560#10571 · In reply to: #10570

Robert Cummings wrote:
> At the end of the array definition or after the last defined array
> entry? If the latter... good feature. Hope it's there to stay since it
> makes cutting and pasting to arrays a lot easier and various other
> automated array building tasks :)

thats exactly what it is in for, saving this tedious last-line-no-komma
flag when generating code :)

and yes, it's there to stay, just a documentation bug that it is not
mentioned yet

-- 
Hartmut Holzgraefe  <hartmut@php.net

---

## #10573 — Red Wingate — 2004-06-17T18:39:15+00:00

URL: https://externals.io/message/10560#10573 · In reply to: #10569

I guess that was <= 4.1.0 as i get errors at work ( 4.0.x ) and 
everything went fine as i misstyped today using 5.0.0rc3 :-)

   --red

Adam Maccabee Trachtenberg wrote:
> 
> 
> 
> > […]
> 
> 
> If I remember correctly, Zeev or Andi specifically added it as a
> result of a user request, so I'd say it's an undocumented feature.
> 
> -adam

---

## #10575 — Mehdi Achour — 2004-06-17T21:34:46+00:00

URL: https://externals.io/message/10560#10575 · In reply to: #10573

This is now [1] a fixed documentation bug :)
I didn't find anything about it in the ChangeLog, nor bugs.php.net,
so I didn't include any version information in the docs.
Drop a mail to the documentation list if you figure it out ;)

didou

[1] - 
http://cvs.php.net/diff.php/phpdoc/en/reference/array/functions/array.xml?r1=1.11&r2=1.12&ty=u


Red Wingate wrote:

> I guess that was <= 4.1.0 as i get errors at work ( 4.0.x ) and 
> everything went fine as i misstyped today using 5.0.0rc3 :-)
> 
>   --red
> 
> Adam Maccabee Trachtenberg wrote:
> 
> > […]

---

## #10576 — Jay Smith — 2004-06-17T22:04:55+00:00

URL: https://externals.io/message/10560#10576 · In reply to: #10575

Mehdi Achour wrote:

> This is now [1] a fixed documentation bug :)
> I didn't find anything about it in the ChangeLog, nor bugs.php.net,
> so I didn't include any version information in the docs.
> Drop a mail to the documentation list if you figure it out ;)
> 
> didou
> 
> [1] -
>
http://cvs.php.net/diff.php/phpdoc/en/reference/array/functions/array.xml?r1=1.11&r2=1.12&ty=u
> 
> 

There's an old bug report for this under bug #550. The whole idea of the
trailing comma is to allow you to easily generate code that's suitable to
pass through eval() or pass from `var_export()` to create a new array. It's a
pretty old feature, as the date of the bug report would show. Not sure the
version it appeared in, though. 

J

---

## #10578 — Andi Gutmans — 2004-06-17T22:51:53+00:00

URL: https://externals.io/message/10560#10578 · In reply to: #10560

This is a supported feature as it especially helps with machine generated 
arrays.
If it's not documented it should be.
Andi

At 04:03 AM 6/17/2004 -0400, Jason Garber wrote:
>Hello,
>
>In PHP4 and PHP5 the following syntax works fine (note the last comma):
>
>array
>(
>     1 => 'bob',
>     2 => 'sam',
>);
>
>
>Is being able to have a comma at the END of an array definition a 
>supported feature, or an undocumented feature that should not be used?
>
>Thanks,
>Jason Garber
>
>
>__________________________________________________________
>Jason Garber
>President & Chief Technology Officer
>IonZoft, Inc.
>814.742.8030 :: jason@ionzoft.com :: http://IonZoft.com
>__________________________________________________________
