tags:

views:

258

answers:

2

What am I doing wrong here?

$array = array('sky'=>'blue', 'grass'=>'green', 'sun'=>'yellow');
$key = array_search('green', $array);
echo $key;

error: Parse error: syntax error, unexpected T_DOUBLE_ARROW in /Applications/XAMPP/xamppfiles/htdocs/search-array.php on line 2

+1  A: 
$array = array('sky'=>'blue', 'grass'=>'green', 'sun'=>'yellow');
$key = array_search('green', $array);
echo $key;

The source you posted works perfectly and returns 'grass'. Are you sure it is not another snippet in your application?

You may want to try finding if you closed the array right and if you have commas where they are needed. If that doesn't resolve it for perfectly functional syntax:

error_reporting(E_ALL^E_NOTICE);
JonnyLitt
I don't get it... I tested in a clean PHP file, those 3 lines only..I copied it exactly to stackoverflow.
FFish
Aye, I updated my answer, try that line of code at the top.
JonnyLitt
Nada! I go and try to install another browser..
FFish
Another browser, that may not help since PHP is server-side..
JonnyLitt
A: 

Long shot, but worth a mention, I feel:

I've had the experience that sometimes, some FTP programs error out silently if they don't manage to transfer the whole file. If you're experiencing the error on a webserver and you pasted us the local code (and only then), that might be what's causing your problem; e.g. if your remote file looks like this due to an incomplete transfer:

$array = array('sky'=>'blue', 'grass'=>'green', 'sun'=>

I've gotten some odd errors over time that I couldn't explain that then boiled down to an incomplete transferred file.

I'd recommend that whenever you encounter a parse error you can't find, try re-uploading the file. If it still occurs, chances are you overlooked something.

(Needless to say that if this does happen to you, you should probably look into a better FTP client. :) Mind, I don't take this advice, I like mine too much, this is its only shortfall.)

pinkgothic