0

So far I have not found any direct explanation. I found out two ways of declaring array. I am basically used to

$myArray = array();

I however found out another way which is:

$myArray = [];

why would anyone use the second option over the first. Is there any difference in terms of memory allocated?

eskoba
  • 532
  • 1
  • 7
  • 25

1 Answers1

2

The first example array() is the way of declaring array until PHP 5.3 after PHP 5.4 the new shorthand way came which is []

There is no such pros and cons using either as per my knowledge of language. The second way provides you with the shorthand method instead of using full version which can be sometimes time consuming and irritating when used for nested array structure...

Sagar Guhe
  • 1,041
  • 1
  • 11
  • 35
  • 1
    Thanks a lot for the answer. for anyone who wants to know its documentation. [here is a link](http://php.net/manual/en/migration54.new-features.php) – eskoba Mar 16 '16 at 11:10