Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

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

From MoodleDocs
Line 23: Line 23:
</code>
</code>


(i.e. brackets and newlines need to be balanced)
(i.e. brackets and newlines need to be balanced, irrespectively of the number of elements per line)

Revision as of 19:38, 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:

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

   $a, $b, $c, 56.44, $d, 500];

(i.e. brackets and newlines need to be balanced, irrespectively of the number of elements per line)