Skip to content
Advertisement

PHP Difference between array() and []

I’m writing a PHP app and I want to make sure it will work with no errors.

The original code:

JavaScript

Would the following work with no errors or is not recommended for some reason?

JavaScript

Are there any difference?

I’ve looked again the data about array() and the short array method with square brackets [] in PHP.net but I’m not sure.

And also, is the short php tag <?= ?> fine for echoing? Is there any version issue? (provided is enabled in php.ini)

Advertisement

Answer

Following [] is supported in PHP >= 5.4:

JavaScript

This is a short syntax only and in PHP < 5.4 it won’t work.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement