Arrays should be formatted with a space separating each element after the comma (,) and spaces around the => key association operator if possible.
Note that if the line declaring an array spans longer than 80 characters, each element should be broken into its own line and indented one level
INCORRECT
// No spacing
// Bad indentation and mixed breaks, inconsistent spacing.
CORRECT
// Spacing as required
// Good indentation, nice breaks, consistent spacing, ends with a ,
The comma at the end of the last array allows the parenthesis to have it´s own line,
it also allows help to prevent parsing errors if another element is placed at the end of the list later.
Note that if the line declaring an array spans longer than 80 characters, each element should be broken into its own line and indented one level
INCORRECT
// No spacing
Code
$my_array = array("apple"=>"red","banana"=>"yellow","watermelon"=>"green");
// Bad indentation and mixed breaks, inconsistent spacing.
Code
$my_array = array(
"apple"=> "red", "banana"=>"yellow",
"watermelon" =>"green",
"Lemon"=> "yellow",
"Strawberry" => "red");
CORRECT
// Spacing as required
Code
$my_array = array("apple" => "red", "banana" => "yellow", "watermelon" => "green");
// Good indentation, nice breaks, consistent spacing, ends with a ,
Code
$my_array = array(
"apple" => "red",
"banana" => "yellow",
"watermelon" => "green",
"Lemon" => "yellow",
"Strawberry" => "red"
);
The comma at the end of the last array allows the parenthesis to have it´s own line,
it also allows help to prevent parsing errors if another element is placed at the end of the list later.