[PHP-DEV] Re: SUMMARY: Array syntax
by Kouber Saparev other posts by this author
Jan 14 2008 7:27AM messages near this date
[PHP-DEV] SUMMARY: Array syntax
|
Re: [PHP-DEV] SUMMARY: Array syntax
A +1 from me (in case my vote counts).
The main reason behind it is readability:
$x = array(1 => array(1, 2, 3), array(array(1), 2));
vs.
$x = [1 => [1, 2, 3], [[1], 2]];
The latter form looks much better to me - it is faster to read and to
understand it (and to type it, of course, although it shouldn't be a
factor), especially for such multi-dimensional definitions.
The benefit of using the new syntax is even bigger when dealing with
function calls + conditionals:
if (in_array($z, array(1, 2, 3))) {
$s = str_replace(array('a', 'b', 'c'), array('d', 'e', 'f'), 'abc');
}
vs.
if (in_array($z, [1, 2, 3])) {
$s = str_replace(['a', 'b', 'c'], ['d', 'e', 'f'], 'abc');
}
With the "square brackets" syntax a pair of redundant parantheses is
removed, thus making it easier to distinguish between data definition
and function call (conditional, expression...) closures and helping
identify arrays among such compound structures. ;-)
Regards,
--
Kouber Saparev
http://kouber.saparev.com
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
Thread:
johannes
Kouber Saparev
Stanislav Malyshev
Tomi Kaistila
Pierre
Steph Fox
Pierre
johannes
Rasmus Lerdorf
Pierre
Sam Barrow
Stanislav Malyshev
Sam Barrow
Antony Dovgal
Sam Barrow
Richard Lynch
Pierre
Antony Dovgal
Jeff Griffiths
Gregory Beaver
Antony Dovgal
Olivier Hill
Sam Barrow
Marcus Boerger
Pierre
Steph Fox
|