I have an array in PHP which is currently populated by manually setting the array line by line in a loop. I increment each 'item' with a simple counter currently, which is what makes each item appear grouped together under that counter. For example:
$item[items][$x][color] = $getColor;
$item[items][$x][size] = $getSize;
Inside of a loop. This results in XML that looks like the following:
<items>
<1>
<color>Blue</color>
<size>XL</size>
</1>
<2>
<color>Red</color>
<size>M</size>
</2>
</items>
This is completely fine, except in order for the data to be read, those numbers need to be something like '' every time, with multiple occurrences. Obviously if I replaced the $x with "shirt" it would be overwritten each time [would work the first time, but all subsequent runs would
I know I'm missing something simple here, and this is existing code so the preference would be to change the initial array somehow vs. simpleXML operations if possible.
Ideal output would look like this:
<iems>
<shirt>
<color>Blue</color>
<size>XL</size>
</shirt>
<shirt>
<color>Red</color>
<size>M</size>
</shirt>
</items>