Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Arrays

Numerically Index Arrays

Each array element should be separated by a comma and a space character. If wrapping an array across multiple lines, subsequent lines should be indented.

Tip
titleCorrect
Code Block
languagephp
$shapes = array("circle", "square", "triangle", "hexagon");
$colors = array(
    "red", "pink",
    "green", "purple"
);

Associative Arrays

Associative arrays should have a space before and after the => assignment. Array indexes should be quoted using single quotes ('). Short arrays can contain all elements on a single line, but it's recommend to set each index on its own line.

Tip
titleCorrect
Code Block
languagephp
$blocks = array(
    'circle' => "red",
    'square' => "pink",
    'triangle' => "green",
    'hexagon' => "purple"
);

Multidimensional Arrays

Each array depth should be indented one level. The ending parenthesis of the array should be indented such that it aligns with the indent level of its defining index.

Tip
titleCorrect
Code Block
languagephp
$polygons = array(
    'triangles' => array(
        "obtuse",
        "acute",
        "right"
    ),
    'quadrilaterals' => array(
        "square",
        "rhombus",
        "rectangle"
    )
);

Constants

Constants should always be capitalized.

...