I have an array that looks like: http://pastebin.com/jtFBeQ88
(Small section of it, use link to see full Array)
string(635) "<InventoryStatus>
<ItemID>171770899535</ItemID>
<Quantity>0</Quantity>
<SKU>0000003830-000011299</SKU>
</InventoryStatus>
<InventoryStatus>
<ItemID>171770899535</ItemID>
<Quantity>0</Quantity>
<SKU>0000003830-000011303</SKU>
</InventoryStatus>
<InventoryStatus>
<ItemID>171770899535</ItemID>
<Quantity>0</Quantity>
<SKU>0000003830-000011583</SKU>
</InventoryStatus>
<InventoryStatus>
<ItemID>171770899535</ItemID>
<Quantity>0</Quantity>
<SKU>0000003830-000013149</SKU>
</InventoryStatus>
<InventoryStatus>
<ItemID>171770899535</ItemID>
<Quantity>0</Quantity>
<SKU>0000003830-000013154</SKU>
</InventoryStatus>
I am trying to extract data in set of 4 elements from InventoryStatus level. An example of this output would look like this.
<InventoryStatus>
<ItemID>171770899535</ItemID>
<Quantity>0</Quantity>
<SKU>0000003830-000011303</SKU>
</InventoryStatus>
<InventoryStatus>
<ItemID>171770899535</ItemID>
<Quantity>0</Quantity>
<SKU>0000003830-000011583</SKU>
</InventoryStatus>
<InventoryStatus>
<ItemID>171770899535</ItemID>
<Quantity>0</Quantity>
<SKU>0000003830-000013149</SKU>
</InventoryStatus>
<InventoryStatus>
<ItemID>171770899535</ItemID>
<Quantity>0</Quantity>
<SKU>0000003830-000013154</SKU>
</InventoryStatus>
I have been using array_slice, but i only seem to be able to specify a count. So if i use 4, then its 4 Nodes down from Top. I could use a count of 20, As each node is always 5. But this is assuming no additional nodes ever get added.
How does one go about doing this, using the Key to extract the data instead of a number.
foreach (array_slice($xmlReq, 4) as $slice) {
echo implode(' ', $slice), "
"; }
Something along the lines of:
foreach (array_slice(xmlReq->InventoryStatus, 4) as $slice {
Echo $slice ."Should show JUST 4 Node sets of InventoryStatus"
}
Maybe array_slice is not the way to go about it, If not what would be more suitable to use