View Full Version : Arrays
dniwebdesign
04-15-2005, 04:12 AM
Array
(
[0] => thegig Object
(
[id] => 1
[day] => 1114840800
[venun] => Louis' Pub
[bandn] =>
[venuw] => http://www.ussu.ca
[bandw] =>
[location] => Saskatoon, Saskatchewan
[time] => 5:00 PM
[nominors] => yes
[extra] => Performing our hit \"Nicole\"!
[status] =>
[tickets] => $10.00
)
[1] => thegig Object
(
[id] => 2
[day] => 1120197600
[venun] => Pasquia Regional Park
[bandn] =>
[venuw] => http://www.pasquia.com
[bandw] =>
[location] => Carrot River, Saskatchewan
[time] => 9:00 PM
[nominors] =>
[extra] => The park is located 6 miles (10 km) south of Carrot River.
[status] =>
[tickets] => $32.00
)
)
I have the above array... Now I know getting the value of just a regular array is
echo $array[0]; But these multi-dimensional, multi-array, thingys... whatever ya wanna call them are throwing me way out. How would I get the values of the inner values like [time], [tickets], etc...
Velox Letum
04-15-2005, 04:21 AM
Try this:
echo $array[0]['id'];
I believe that is how you display a multidimensional array, but don't count me on it...I havn't used them much.
dniwebdesign
04-15-2005, 04:53 AM
Well, she doesn't seem to be turning anything up so either your wrong or I'm doing something wrong. But I don't know how I can screw up on something that seems so simple. Thanks for the try though... Anybody else wanna confirm whether he's right or wrong?
mordred
04-15-2005, 08:29 AM
What Velox Letum posted is essentially correct. It might not have worked for you because you probably used wrong variable/key names. To get more help, I recommend that you post real PHP code of your multi-dimensional array. Possibly only a short snapshot that exemplifies the problem. What you posted above looks like the output of a print_f() call, but that's not code, only a textual representation of it.
dniwebdesign
04-15-2005, 09:42 AM
$simple = "http://www.utexts.ca/giglist3_1/gigs.xml.php";
class theGIG {
var $id; // GIG ID
var $day; // Date of GIG, Unix Timestamp
var $venun; // Venu Name
var $bandn; // Band Name
var $venuw; // Venu Website
var $bandw; // Venu Website
var $location; // Location of GIG
var $time; // Time of GIG
var $nominors; // No Minors?
var $extra; // Extra info about GIG
var $status; // Current status of GIG
function theGIG($aa)
{
foreach ($aa as $k=>$v)
$this->$k = $aa[$k];
}
}
function readDatabase($filename)
{
// read the XML database of gigs
$data = implode("", file($filename));
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, $data, $values, $tags);
xml_parser_free($parser);
// loop through the structures
foreach ($tags as $key=>$val) {
if ($key == "gig") {
$molranges = $val;
// each contiguous pair of array entries are the
// lower and upper range for each gig definition
for ($i=0; $i < count($molranges); $i+=2) {
$offset = $molranges[$i] + 1;
$len = $molranges[$i + 1] - $offset;
$tdb[] = parseMol(array_slice($values, $offset, $len));
}
} else {
continue;
}
}
return $tdb;
}
function parseMol($mvalues)
{
for ($i=0; $i < count($mvalues); $i++) {
$mol[$mvalues[$i]["tag"]] = $mvalues[$i]["value"];
}
return new theGIG($mol);
}
$db = readDatabase($simple);
echo "<pre style='font-family: Arial; font-size: 12px;'>";
print_r($db);
echo "</pre>";
marek_mar
04-15-2005, 03:24 PM
To make it short:
$array_name[0]->id
It's a noraml array which holds objects which have properies (if you'd ask me).
dniwebdesign
04-15-2005, 09:30 PM
To make it short:
$array_name[0]->id
It's a noraml array which holds objects which have properies (if you'd ask me).
Works like a charm. Thanks.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.