1

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

4
  • 3
    It's parsing properly for me. Are you sure there isn't a typo in your source that isn't present here? Commented Mar 16, 2010 at 23:30
  • 1
    works for me nicely,is this the right code? Commented Mar 16, 2010 at 23:31
  • wtf? I pasted it from my search-array.php test file here at stackoverflow... Commented Mar 16, 2010 at 23:34
  • What version of PHP are you using? Are you on Windows or Linux? What is the file encoding? Commented Mar 19, 2010 at 17:20

2 Answers 2

1
$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);
Sign up to request clarification or add additional context in comments.

1 Comment

I don't get it... I tested in a clean PHP file, those 3 lines only.. I copied it exactly to stackoverflow.
0

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.)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.