You want to use Xpath for this. It's basically exactly the same as outlined in SimpleXML: Selecting Elements Which Have A Certain Attribute Value but in your case you're not deciding on an attribute value but on an element value.
However in Xpath for both the element you're looking for is the parent.So formulating the xpath expression is kind of straight forward:
// Here we find the item element that has the child <id> element
// with node-value "12437".
list($result) = $data->xpath('(//items/item[id = "12437"])[1]');
$result->asXML('php://output');
Output (beautified):
<item>
<title>title of 12437</title>
<id>12437</id>
</item>
So let's see the heart of this xpath query again:
//items/item[id = "12437"]
It's written as: Select all <item>
elements that are a children of any <items>
elements which on their own have a child element named <id>
with the value "12437"
.
And now with the missing stuff around:
(//items/item[id = "12437"])[1]
The parenthesis around says: From all these <item>
elements, pick the first one only. Depending on your structure this might or might not be necessary.
So here is the full usage example and online demo:
<?php
/**
* php simplexml get a specific item based on the value of a field
* @lin https://stackoverflow.com/q/17537909/367456
*/
$str = <<<XML
<items>
<item>
<title>title of 43534</title>
<id>43534</id>
</item>
<item>
<title>title of 12437</title>
<id>12437</id>
</item>
<item>
<title>title of 7868</title>
<id>7868</id>
</item>
</items>
XML;
$data = new SimpleXMLElement($str);
// Here we find the item element that has the child <id> element
// with node-value "12437".
list($result) = $data->xpath('(//items/item[id = "12437"])[1]');
$result->asXML('php://output');
So what you call a field in your questions title is by the book a child-element. Keep this in mind when searching for more complicated xpath queries that get you what you're looking for.