Sunday, January 6, 2019

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:



$data = array('name' => 'test',
'id' => 'theID');

echo form_input($data);
?>



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



 'test', 'id' => 'theID']); ?>


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)


Answer



Following [] is supported in PHP >= 5.4:



['name' => 'test', 'id' => 'theID']


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


No comments:

Post a Comment

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...