Dowdy Posted August 18, 2008 Share Posted August 18, 2008 hi, I am parsing XML to my script and converting it to an array. All the Details are going through successfully but I can't seem to reference the data for use. When I view source it is displayed like this Array ( [array] => Array ( [serverID] => 10 [serverType] => Shoutcast [MaxUsers] => 50 [sourcePassword] => TestSource [RelayPort] => 1 [RelayPublic] => Never [AutoDump] => 0 [AdminPassword] => TestAdmin [MaxBandwidth] => 300 [bitRate] => 96 ) ) I am trying to use ServerType as a switch for a case statement but I can't seem to reference it correctly. I have tried $array['array'] ['ServerType'], $array['ServerType'], $array['0']['ServerType'] and as many variations that have come to mind, to no avail. Any help would be much appreciated Thanks Link to comment https://forums.phpfreaks.com/topic/120170-solved-refferring-to-array/ Share on other sites More sharing options...
trq Posted August 18, 2008 Share Posted August 18, 2008 $array[0]['ServerType'] Link to comment https://forums.phpfreaks.com/topic/120170-solved-refferring-to-array/#findComment-619077 Share on other sites More sharing options...
Dowdy Posted August 18, 2008 Author Share Posted August 18, 2008 Thanks for the reply, That didn't work either though. I can see the whole array with print_r($ServerDetails) within my script, which is the name of the origional array before it was parsed. Not sure what else to try Link to comment https://forums.phpfreaks.com/topic/120170-solved-refferring-to-array/#findComment-619105 Share on other sites More sharing options...
Dowdy Posted August 19, 2008 Author Share Posted August 19, 2008 Here's the code i'm having issues with and I have attached the include file that deals with the conversion <?PHP include $_SERVER["DOCUMENT_ROOT"].'\libXML.php'; $array=array("ServerID" => "10", "ServerType" => "Shoutcast", "MaxUsers" => "50", "SourcePassword" => "TestSource", "RelayPort" => "1", "RelayPublic" => "Never", "AutoDump" => "0", "AdminPassword" => "TestAdmin", "MaxBandwidth" => "300", "BitRate" => "96"); //Demo Array $converter= new assoc_array2xml; $XML=$converter->array2xml($array); $XML = stripslashes($XML); //Need to strip slashes otherwise it won't convert back to array $ServerDetails = $converter->xml2array($XML); print_r($ServerDetails); echo($array[0]['ServerType']); ?> [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/120170-solved-refferring-to-array/#findComment-619926 Share on other sites More sharing options...
Dowdy Posted August 19, 2008 Author Share Posted August 19, 2008 Sorry this is a bit of a bump but im still stumped! Has anyone tried the code? Oh make sure to change the include to "include 'libXML.php';" and run the two from the same directory ! Link to comment https://forums.phpfreaks.com/topic/120170-solved-refferring-to-array/#findComment-620231 Share on other sites More sharing options...
trq Posted August 20, 2008 Share Posted August 20, 2008 <?php include 'libXML.php'; $array = array( "ServerID" => "10", "ServerType" => "Shoutcast", "MaxUsers" => "50", "SourcePassword" => "TestSource", "RelayPort" => "1", "RelayPublic" => "Never", "AutoDump" => "0", "AdminPassword" => "TestAdmin", "MaxBandwidth" => "300", "BitRate" => "96" ); $converter= new assoc_array2xml; $XML=$converter->array2xml($array); $XML = stripslashes($XML); $ServerDetails = $converter->xml2array($XML); print_r($ServerDetails); echo($ServerDetails['array']['ServerType']); ?> Link to comment https://forums.phpfreaks.com/topic/120170-solved-refferring-to-array/#findComment-620626 Share on other sites More sharing options...
Dowdy Posted August 20, 2008 Author Share Posted August 20, 2008 that works perfectly, thank you so much. that had me stumped for so long Link to comment https://forums.phpfreaks.com/topic/120170-solved-refferring-to-array/#findComment-620934 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.