Howdy guys and girls. Been a long time since I've been in these parts.
My php is rusty these days, so please bare with me. I'm trying to
create a dynamic, multidimensional array, and keep track of which level
I'm on, opening and closing levels as needed. Lets say that I have some
data like the below:
Array
(
[0] => Array
(
[tag] => OrderFeed
[type] => open
[level] => 1
[attributes] => Array
(
[version] => 1.0
)
[value] => -
)
[1] => Array
(
[tag] => Order
[type] => open
[level] => 2
[value] => -
)
[2] => Array
(
[tag] => OrderId
[type] => open
[level] => 3
)
[3] => Array
(
[tag] => E4XOrderId
[type] => complete
[level] => 4
[value] => E4X000000000001
)
[4] => Array
(
[tag] => MerchantOrderId
[type] => complete
[level] => 4
[value] => Mrc0000001
)
[5] => Array
(
[tag] => MerchantOrderRef
[type] => complete
[level] => 4
[value] => ABCDEFGHI000001
)
[6] => Array
(
[tag] => OrderId
[type] => close
[level] => 3
)
[7] => Array
(
[tag] => Order
[value] => -
[type] => cdata
[level] => 2
)
[8] => Array
(
[tag] => OrderDate
[type] => open
[level] => 3
)
[9] => Array
(
[tag] => CreateDate
[type] => complete
[level] => 4
[value] => 12-03-2007
)
[10] => Array
(
[tag] => ExpiryDate
[type] => complete
[level] => 4
[value] => 12-15-2007
)
)
I create an empty array before I start looping through this data:
$newArray = array();
Now, when looping through the data, every time I encounter a 'tag' that
is of the open 'type' I need to create a new array within the base array
with the value of 'tag' as the index:
$newArray['OrderFeed']
$newArray['OrderFeed']['Order']
$newArray['OrderFeed']['Order']['OrderID']
So on and so forth. When I get to a 'tag' that is of the 'type'
complete, I need to make that a name value pair in the current level of
the array:
Array
(
[OrderFeed] => Array
(
[Order] = Array
(
[OrderID] = Array
(
[CreateDate] => 12-03-2007
)
)
)
)
And when I get to 'tag' of the close 'type', I need to move up one level
in the array. I have tried using another array just to keep track of
what level of the array I'm currently on, but I can seem to figure out
how to form the master array out of it. In the above example, I would
have an array with the 'OrderFeed', 'Order' and 'OrderID' as the three
elements in it. If I encounter and 'open' tag, I add that value onto
the end of the 'tracking' array, and when I encounter a 'close' tag, I
just pop the last element off of the tracking array. So basically, I'm
trying to take the values in my 'tracking' array....
Array
(
OrderFeed,
Order,
OrderID
)
And somehow, use them to keep track of where I am in the dynamic
$newArray. I hope this makes sense....I know what I want to do in my
head, but I'm not sure I'm getting it out well here. Any suggestions?
Questions?
--
John C. Nichel IV
System Administrator
KegWorks
http://www.kegworks.com
716.362.9212 x16
[email protected]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php