1

I am getting error when I upload on shared hosting but in local computer works fine.

My code is below:

<?php
$arr = ["one","two","three"];
echo $arr[0];
?>

current error:

Parse error: syntax error, unexpected '[' in /home/jacky/public_html/test.php on line 2
Boricua
  • 21
  • 3
  • Your shared hosting has a lower version of php installed than you need to use the short array syntax (you need >=5.4) – Clive Dec 13 '14 at 16:23
  • You can upgrade your PHP version. Now many scripts are written with this style type array. If you use latest written script you have to upgrade your PHP version. – Touhid Dec 13 '14 at 16:31
  • possible duplicate of [SVN Commit failed with syntax error, unexpected '\['](http://stackoverflow.com/questions/19548026/svn-commit-failed-with-syntax-error-unexpected) – Rangad Dec 13 '14 at 16:33

1 Answers1

5

I think your PHP version is under 5.4 so you can use [].

You have to use this:

$arr = array("one","two","three");
echo $arr[0];

For more information see: http://php.net/manual/en/language.types.array.php

Rizier123
  • 58,877
  • 16
  • 101
  • 156
  • 1
    However, PHP version < 5.4 are no longer officially maintained. If one is not on a distribution that maintains 5.3 itself (e.g. old-stable debian) one should really consider upgrading to a php version that still receives security updates. – Rangad Dec 13 '14 at 16:30