devWhiz Posted August 10, 2011 Share Posted August 10, 2011 I use simplexml to parse the xml that is like this <xml> <data> <id>15</id> <age>18</age> <name>name</name> </data> <data> <id>23</id> <age>19</age> <name>name2</name> </data> <xml> I want to be able to grab the age and name like this $array[$id]['age']; $array[$id]['name']; where $id equals the id in each data element.. I want to get the age and name randomly use $id = rand(1,30); but I dont know how to set up the array, any help is appreciated Link to comment https://forums.phpfreaks.com/topic/244438-how-would-i-get-this-xml-data-into-an-array/ Share on other sites More sharing options...
Maq Posted August 10, 2011 Share Posted August 10, 2011 Do you absolutely require an array? Why don't you load it into something like an simplexml object and use XPath. Link to comment https://forums.phpfreaks.com/topic/244438-how-would-i-get-this-xml-data-into-an-array/#findComment-1255547 Share on other sites More sharing options...
devWhiz Posted August 11, 2011 Author Share Posted August 11, 2011 I could do that but the script I wrote worked around values in an array Array ( [25] => Array ( [Name] => Clueless [Age] => 18 ) [15] => Array ( [Name] => Name2 [Age] => 20 ) ) and then I could call it like this $id = 20; echo $array[$id]['name']; // this would be name2 Link to comment https://forums.phpfreaks.com/topic/244438-how-would-i-get-this-xml-data-into-an-array/#findComment-1255653 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.