xml-to-array
xml-to-array copied to clipboard
Fixed issue with duplicate checker by using `array_count_values()` to determine if a node has the same name
Hi @vyuldashev 👋
Thank you for this great little package, it's helped me massively with a project we've had to built quickly. I ran into a small issue however which was with some of the XML I was processing. One section of the XML had the following child nodes:
<Products>
<Products>
<ProductCount>
I found an issue where the sameName variable wouldn't be true because of the last <ProductCount> child node causing the isHomogenous method to return false.
I have solved this issue by using array_count_values which will count up all of the occurrences of each of the duplicated nodes, and when it checks to see if a node already exists, we check the $sameNamesOccurrences array for duplicates.
All tests are passing fine and it seems to work for my solution too. I hope you get a chance to review and potentially accept this PR! 🤓
Have a great day. ☀️
Ah, I just figured out another potential bug with the keys. For example if you have two different nodes that both have child nodes, the keys aren't reset so you get the following:

With the latest commit:
