I have a dynamic number of multidimensional arrays, named like $market1, $market2, $market3... These arrays are formed (simplexml_load_file()) from XML files which have the following structure:
SimpleXMLElement Object
(
[@attributes] => Array
(
[version] => 2.0
[method] => marketstat_xml
)
[marketstat] => SimpleXMLElement Object
(
[type] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 25268
)
[buy] => SimpleXMLElement Object
(
[volume] => 68049
[avg] => 79171.90
[max] => 85251.27
[min] => 71005.66
[stddev] => 5187.52
[median] => 80030.04
[percentile] => 85250.46
)
[sell] => SimpleXMLElement Object
(
[volume] => 13052
[avg] => 407071.42
[max] => 79000000.00
[min] => 98000.00
[stddev] => 27607034.09
[median] => 104990.00
[percentile] => 104689.17
)
[all] => SimpleXMLElement Object
(
[volume] => 91051
[avg] => 74144.16
[max] => 120000.00
[min] => 23.50
[stddev] => 19857.57
[median] => 83351.92
[percentile] => 23.50
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[id] => 28694
)
[buy] => SimpleXMLElement Object
(
[volume] => 285000
[avg] => 1610.29
[max] => 2011.64
[min] => 801.01
[stddev] => 386.84
[median] => 1824.15
[percentile] => 2011.64
)
[sell] => SimpleXMLElement Object
(
[volume] => 53287
[avg] => 4560.18
[max] => 9998.00
[min] => 3811.63
[stddev] => 2446.09
[median] => 4189.46
[percentile] => 3811.63
)
[all] => SimpleXMLElement Object
(
[volume] => 343309
[avg] => 1912.47
[max] => 4798.00
[min] => 23.50
[stddev] => 1340.91
[median] => 2011.55
[percentile] => 671.43
)
)
[...]
In every array there are several itemids, and I want to read out the values of specific ones. Something like this does not work (and I didn't expect it to)
print ${"market".$number}->marketstat->$id->buy->max;
I could solve it over an ugly foreach() construct I guess, but there has to be a better way. What is the best (fastest, elegant) way to give out the value under that specific market and that specific itemid?