I have xml file.
<shop>
<categories>
<category id="132">kids</category>
<category id="62" parentId="133">women</category>
<category id="172" parentId="1">men</category>
</categories>
<materials>
<material id="1">one</material>
<material id="2">two</material>
<material id="3">soon</material>
</materials>
<offers>
<offer id="41850" available="true">
<price>3220</price>
<currencyId>EUR</currencyId>
<date>2015-02-05</date>
</offer>
<offer id="41850" available="true">
<price>3220</price>
<currencyId>EUR</currencyId>
<date>2015-02-05</date>
</offer>
<offer id="41850" available="true">
<price>3220</price>
<currencyId>EUR</currencyId>
<date>2015-02-05</date>
</offer>
<offer id="77777" available="true">
<price>3250</price>
<currencyId>EUR</currencyId>
<date>2015-02-05</date>
</offer>
<offer id="41340" available="true">
<price>3120</price>
<currencyId>EUR</currencyId>
<date>2015-02-05</date>
</offer>
I need delete categories and materials. After that i need delete all offers which are not unique and write it to new xml file.
My problem. I can't delete not unique offers. Please help me! Thx. Here is my code.
$url = 'test.xml';
$yml = simplexml_load_file($url);
unset($yml->shop->categories);
unset($yml->shop->materials);
$itemid = '0';
foreach ($yml->shop->offers->offer as $item){
$sravnit = $item['id'];
if("$sravnit" == "$itemid") {
echo "$sravnit eq $itemid delete<br>";
unset($yml->shop->offers->offer[$sravnit]);
continue;
else {echo "$sravnit not eq $itemid ";
$itemid = $sravnit;
echo "itemid to - $itemid <br>";
}
}
$yml->asXML('odd.xml');