Skip to content

Commit a949bf5

Browse files
feature/arrays new section clarifying array usage
1 parent 9dc210d commit a949bf5

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

spec.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,45 @@ function allowed()
13171317
}
13181318
```
13191319

1320+
## 12. Arrays
1321+
1322+
Arrays MUST be declared using the short array syntax.
1323+
1324+
```php
1325+
<?php
1326+
1327+
$arr = [];
1328+
```
1329+
1330+
Arrays MUST follow the trailing comma guidelines.
1331+
1332+
Array declarations MAY be split across multiple lines, where each subsequent line
1333+
is indented once. When doing so, the first value in the array MUST be on the
1334+
next line, and there MUST be only one value per line.
1335+
1336+
When the array declaration is split across multiple lines, the opening bracket
1337+
MUST be placed on the same line as the equals sign. The closing bracket
1338+
MUST be placed on the next line after the last value. There MUST NOT be more
1339+
than one value assignment per line. Value assignments MAY use a single line
1340+
or multiple lines.
1341+
1342+
```php
1343+
<?php
1344+
1345+
$arr1 = ['single', 'line', 'declaration'];
1346+
1347+
$arr2 = [
1348+
'multi',
1349+
'line',
1350+
'declaration',
1351+
['values' => 1, 5, 7],
1352+
[
1353+
'nested',
1354+
'array',
1355+
],
1356+
];
1357+
```
1358+
13201359
[PSR-1]: https://www.php-fig.org/psr/psr-1/
13211360
[PSR-12]: https://www.php-fig.org/psr/psr-12/
13221361
[keywords]: http://php.net/manual/en/reserved.keywords.php

0 commit comments

Comments
 (0)