Syntax:array (key = > value, key2 = > value2, key3 = > value3, ...)
The comma after the last element of the array is not required, but it can help other developers understand if the array is being updated or not. This is usually done for single-line arrays, i.e. array (1, 2) is preferred over array (1, 2,). On the other hand, a trailing comma is usually used for multi-line arrays because it makes it easier to add new elements to the end of an existing array.
Note.The only difference is using [] or array() depends on the PHP version you are using. In PHP 5.4, you can also use the short array syntax, which replaces array() with [].
Example :
$array
=
array
(
"geek"
= >
"tech"
,
"tech "
= >
" geek "
,
);
var_dump (
$array
);
// Since PHP 5.4
$array
= [
"geek"
= >
"tech"
,
"tech"
= >
"geek"
,
];
var_dump (
$array
);
?>
Output:array (2) {["geek"] = > string (4) "tech" ["tech"] = > string (4) "geek"} array (2) {["geek"] = > string (4) "tech" ["tech"] = > string (4) "geek"}