Jump to content

[SOLVED] Refferring to Array


Dowdy

Recommended Posts

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

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]

<?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']);

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.