-4

I keep getting the following error when building an array:

PHP Parse error:  syntax error, unexpected ';', expecting ')'

for the following code:

$fetchResult=$PubMedClient->run_eFetch(array(
'db'=>'pubmed',
'id'=>(count($searchResult->IdList->Id)>1 ? join(",",$searchResult->IdList->Id) : $searchResult->IdList->Id)));

I've tried to break this up in many ways, but it does not work. As usual, I'm sure it is something simple that I'm just not seeing.

Anyone have an idea?

Many thanks

4
  • 2
    Put another ) before ; at the end of your code?
    – N.B.
    Commented Jun 13, 2013 at 14:22
  • Another closing ) is required at the end. You've not closed your run_eFetch function
    – NoGall
    Commented Jun 13, 2013 at 14:23
  • Do you want us to count your brackets? Use a decent IDE or count them yourself.
    – CodeCaster
    Commented Jun 13, 2013 at 14:24
  • Try to learn how to decipher the error messages :)
    – aletzo
    Commented Jun 13, 2013 at 14:24

1 Answer 1

2

It would be slightly easier to read if you broke out the ternary operation into a variable like so:

$getID = count($searchResult->IdList->Id) > 1 ? join(",", $searchResult->IdList->Id) : $searchResult->IdList->Id;

$fetchResult = $PubMedClient->run_eFetch(
    array(
        'db'=>'pubmed',
        'id'=> $getID
    )
);

The above should work.

1
  • Many thanks for the responses. I did close with the last bracket ")" before the semicolon, but that was not working either.
    – Ken
    Commented Jun 13, 2013 at 14:39

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.