Drupal is full of arrays, even in Drupal 8. But when you look at an array in Drupal 8, you may be left wondering why they look different to how they looked in Drupal 7. The reason is that the Drupal code standards now recommend using short array syntax.
Short array syntax was added to PHP in PHP 5.4 and replaces array() with [].
This is how it used to look with the long array syntax:
$array = array(
"foo" => "bar",
"bar" => "foo",
);
This is how it looks now with the newer shortened syntax:
$array = [
"foo" => "bar",
"bar" => "foo",
];
Comments
Comment #3
beram commentedComment #5
pankajchaudhari commentedDrupal is full of arrays, even in Drupal 8. But when you look at an array in Drupal 8, you may be left wondering why they look different to how they looked in Drupal 7. The reason is that the Drupal code standards now recommend using short array syntax.
Short array syntax was added to PHP in PHP 5.4 and replaces array() with [].
This is how it used to look with the long array syntax:
$array = array(
"foo" => "bar",
"bar" => "foo",
);
This is how it looks now with the newer shortened syntax:
$array = [
"foo" => "bar",
"bar" => "foo",
];
To see examples of this, check out this week's tutorial:
Read the introduction to PHP short array syntax