I'm not a usual php user but till now I always used to declare arrays in this way:
$arr = ["id" => 15,"val" => 13];
In my local xampp (PHP Version 5.5.9) environment this worked fine, but on server (PHP Version 5.3.28) this code fails giving:
PHP Parse error: syntax error, unexpected '[' in /web/htdocs/site.sit/home/pdo.php on line 24
I switched the declaration to this and everything is ok,
$arr = array("id" => 15,"val" => 13)
But I want to understand why this error occurred As documentation states it is not a matter of deprecated code and I see that the first example is using my first array declaration with the comment note
// as of PHP 5.4
What does it means?
Anyway I suspect that its a problem related with some sort strict mode.
array()
has always been the way to declare arrays in PHP since before the dawn of time. In PHP 5.4, the shorter []
has been introduced, simply because it's shorter and many other languages use it too. []
doesn't work in 5.3 or below. TFM documents that.