P
P
PHPshnick2019-05-13 17:23:17
PHP
PHPshnick, 2019-05-13 17:23:17

How to remove extra elements from XML using PHP?

Good day everyone!
I have a big xml-file where the goods are described. Goods have many properties, and the main thing is that the same goods differ in one parameter (for example, the amount of memory) and these goods are in different warehouses. Sample file content:

<good productCode="AMDFX6RAD8SSD2X">
    <name>Комплюктер большой чёрный</name>
    <attribute name="Процессор" value="AMD"/>
    <attribute name="Память" value="оперативная"/>
    <attribute name="HDD" value="SSD"/>
    <prices>
      <baseprice>99000.00</baseprice>
      <price group="1">55000.00</price>
      <price group="2">74000.00</price>
    </prices>
    <memory>
      <stock id="236347474" name="Склад в доках" memory="2000" quantity="1"/>
      <stock id="6593467303" name="Склад на складе" memory="2000" quantity="1"/>
      <stock id="356956539" name="Склад на улице" memory="1200" quantity="1"/>
      <stock id="35696359" name="Склад в бункере" memory="1000" quantity="1"/>
      <stock id="2352323" name="Просто на улице лежит" memory="1000" quantity="1"/>
    </memory>
  </good>

As you can see, there are goods of the same characteristics that are in different warehouses. I need to make sure that as many unique products appear from one good entry as there are unique products in the list. That is, the algorithm is as follows:
1. Remove duplicate lines from the " memory " list;
2. Generate a new good entry under each " memory " entry.
Actually, I roughly imagine the solution algorithm itself, but I don’t know how to implement it in php.
Help me please.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question