Reputation: 28030
I am going to construct a highly complex associative array in php. But first, I need to initialize it.
What is the right way to initialize it? My initialization is as follows;
$ComplexAssociativeArray = [];
Are there better ways?
Upvotes: 1
Views: 891
Reputation: 27845
If you go for
$array = [
"foo" => "bar",
"bar" => "foo",
];
It wont work in php versions before 5.4
but below way work in all versions
$array = array(
"foo" => "bar",
"bar" => "foo",
);
I think that is the main difference.
Quoting from php docs for arrays
As of PHP 5.4 you can also use the short array syntax, which replaces array() with [].
Upvotes: 3