Question about array opening in PHP

0

By typing arrays in PHP, I ended up finding some different ways to open an array, but in the end they have the same destination, for example:

$arr = [
   'dado' => ''
];

Or

$arr = array(
  'dado' => ''
);

Or

$arr['dado'] = '';

And in another context, adding keys:

$a = 1;
while($a <= 10){
   $arr[$a] = 'dado'.$a;
   $a++
}

Is there any relevant difference in these different ways to open an array?

What would be the most 'correct' way to open an array?

    
asked by anonymous 09.08.2017 / 15:53

1 answer

0

Yes it exists (when using, both generate the same result as an array.), the compact syntax ( [] ) is only available from 5.4 for earlier versions only array() works. To keep code more compatible if it is a library it is recommended to use the traditional syntax array() .

    
09.08.2017 / 15:56