Selecting only the first item of an xpath result set in PHP

Posted by IkimashoZ on Stack Overflow See other posts from Stack Overflow or by IkimashoZ
Published on 2010-05-06T03:01:06Z Indexed on 2010/05/06 3:08 UTC
Read the original article Hit count: 237

Filed under:
|

I am currently achieving the desired outcome with two PHP statements:

$thisBlarg = $xmlResource->xpath('//blarg[@ID='.$someBlargID.']');
echo $thisBlarg[0]->name;

But, not wanting to settle for second best, I'd really prefer this to be one statement, but PHP doesn't like this:

echo $xmlResource->xpath('//blarg[@ID='.$someBlargID.']')[0]->name;

And for good reason. But I can't find a way to force an xpath query to return the result directly. Any suggestions?

© Stack Overflow or respective owner

Related posts about php

Related posts about xpath