php - how to parse an xml and show only the row where there is a particular value?



I have an xml which is similar to this:



<xml>
<products name="product_list">
<product id="1" name="product_1">Soap</product>
<product id="2" name="product 3">Shampoo</product>
<product id="3" name="product_3">Sponge</product>
</products>
</xml>


I'm trying to import it via php (using simplexml) but I would like show only one row where the id match another variable I've set.


Something like :



echo product where product['id'] = $variable


But I have no idea how to do that.


Tiada ulasan:

Catat Ulasan