Skip to content

Added Arrays as Section 12 #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 10, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,45 @@ function allowed()
}
```

## 11. Arrays

Arrays MUST be declared using the short array syntax.

```php
<?php

$arr = [];
```

Arrays MUST follow the trailing comma guidelines.

Array declarations MAY be split across multiple lines, where each subsequent line
is indented once. When doing so, the first value in the array MUST be on the
next line, and there MUST be only one value per line.

When the array declaration is split across multiple lines, the opening bracket
MUST be placed on the same line as the equals sign. The closing bracket
MUST be placed on the next line after the last value. There MUST NOT be more
than one value assignment per line. Value assignments MAY use a single line
or multiple lines.

```php
<?php

$arr1 = ['single', 'line', 'declaration'];

$arr2 = [
'multi',
'line',
'declaration',
['values' => 1, 5, 7],
[
'nested',
'array',
],
];
```

[PSR-1]: https://www.php-fig.org/psr/psr-1/
[PSR-12]: https://www.php-fig.org/psr/psr-12/
[keywords]: http://php.net/manual/en/reserved.keywords.php
Expand Down