Difference between revisions of "User:Eloy Lafuente (stronk7)/Arrays"

Jump to: navigation, search
(Created page with "===Numerically indexed arrays=== When declaring arrays, a trailing space must be added after each comma delimiter to improve readability: <code php> $myarray = [1, 2, 3, 'St...")
 
(Numerically indexed arrays)
 
(4 intermediate revisions by the same user not shown)
Line 8: Line 8:
  
 
Multi-line indexed arrays are fine, but pad each successive lines as above with an 4-space indent:
 
Multi-line indexed arrays are fine, but pad each successive lines as above with an 4-space indent:
 +
 +
<code php>
 +
$myarray = [1, 2, 3, 'Stuff', 'Here',
 +
    $a, $b, $c, 56.44, $d, 500];
 +
</code>
 +
 +
Note that the example above also can be written as follows:<br/>
 +
(with special attention to the last line having a trailing comma to extend the list of items later with a cleaner diff)
  
 
<code php>
 
<code php>
Line 16: Line 24:
 
</code>
 
</code>
  
Note that the example above also can be written:
+
In any case, brackets and newlines need to be balanced, irrespectively of the number of elements per line.
 
 
<code php>
 
$myarray = [1, 2, 3, 'Stuff', 'Here',
 
    $a, $b, $c, 56.44, $d, 500];
 
</code>
 
 
 
(i.e. brackets and newlines need to be balanced. And the 4 additional spaces can be used for readability as specified @ [[#Wrapping_lines]]
 

Latest revision as of 20:59, 20 May 2020

Numerically indexed arrays

When declaring arrays, a trailing space must be added after each comma delimiter to improve readability:

$myarray = [1, 2, 3, 'Stuff', 'Here'];

Multi-line indexed arrays are fine, but pad each successive lines as above with an 4-space indent:

$myarray = [1, 2, 3, 'Stuff', 'Here',
    $a, $b, $c, 56.44, $d, 500];

Note that the example above also can be written as follows:
(with special attention to the last line having a trailing comma to extend the list of items later with a cleaner diff)

$myarray = [
    1, 2, 3, 'Stuff', 'Here',
    $a, $b, $c, 56.44, $d, 500,
];

In any case, brackets and newlines need to be balanced, irrespectively of the number of elements per line.