Formatting associative array declaration
- by Drew Stephens
When declaring an associative array, how do you handle the indentation of the elements of the array? I've seen a number of different styles (PHP syntax, since that's what I've been in lately). This is a pretty picky and trivial thing, so move along if you're interested in more serious pursuits.
1) Indent elements one more level:
$array = array(
'Foo' => 'Bar',
'Baz' => 'Qux'
);
2) Indent elements two levels:
$array = array(
'Foo' => 'Bar',
'Baz' => 'Qux'
);
3) Indent elements beyond the array constructor, with closing brace aligned with the start of the constructor:
$array = array(
'Foo' => 'Bar',
'Baz' => 'Qux'
);
4) Indent elements beyond the array construct, with closing brace aligned with opening brace:
$array = array(
'Foo' => 'Bar',
'Baz' => 'Qux'
);
Personally, I like #3—the broad indentation makes it clear that we're at a break point in the code (constructing the array), and having the closing brace floating a bit to the left of all of the array's data makes it clear that this declaration is done.