|
Posted by Andy Hassall on 05/29/05 01:19
On Sat, 28 May 2005 22:10:58 GMT, "Hello" <no-emai@sorry.com> wrote:
>I use PHP 5.01. Could you see if it works in other vesions?
>
>If you declare an array:
>
>$a=array(1,2,3,4,5,); <------no error, even though there is a COMMA after
>"5"
This works in all versions of PHP I've seen, and a similar thing works in Perl
and array initialisation in C.
Its main use is either for programmer laziness (you can just stick a comma on
the end of each item, and you don't have to think about adding or removing
commas if you re-order the values) or to simplify code-generation programs (so
they don't have to worry about not putting a comma on the final item).
It looks a bit funny as a one liner but less so when split across lines,
$a = array(
1,
2,
3,
4,
5,
);
The same doesn't apply to function parameters, though - a trailing comma
produces a parse error.
--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
[Back to original message]
|