Saturday, March 3, 2012

PHP5.4 short array syntax

We used to define an array using the array() language construct:
array(
 key => value,
 key2 => value2,
 key3 => value3,
)

As of PHP 5.4 you can also use the short array syntax, which replaces array() with [].
$array = [
 "foo" => "bar",
 "bar" => "foo"
];
Good to see that we have another flexibility and can be lazier. But, to developers who highly agree with Python's philosophy 'There should be one-- and preferably only one --obvious way to do it', this may not be necessarily good. Another rule must be added in their development teams to specify which style should be used in projects.

No comments: