Home > DeveloperSection > Forums > Declare php array as javascript array situation
Mark Devid
Mark Devid

Total Post:102

Points:714
Posted on    May-15-2013 8:13 AM

 PHP PHP 
Ratings:


 1 Reply(s)
 1167  View(s)
Rate this:
Hi Expert!

I was unable to find an answer to this situation that I have stumbled uppon this morning. I have declared some php variables as I usually do in javascript (by mistake). I was surprised that the code actually worked. I have tested it under Linux and it works fine. Under WAMP on Windows does not work.

The code:

<?php

error_reporting(E_ALL);

$phones = [];

var_dump($phones);

?>
Result in Linux:

array(0) {
}
Result in Windows:

Parse error: syntax error, unexpected '[' in D:\wamp\www\test.php on line 7
Question: Is this a valid declaration of an array in php?

Thanks in advance! 



AVADHESH PATEL

Total Post:604

Points:4228
Posted on    May-15-2013 8:54 AM

Hi Mark!

The [] syntax is valid only in PHP 5.4 or newer, check your PHP version on windows.

I hope it helpful for you.

Don't want to miss updates? Please click the below button!

Follow MindStick