I need to reference a global multidimensional array inside my function, but $GLOBALS["CSSArray["$arg_1"]["$arg_2"]"] doesn't seem to work. Has anyone else run into this and solved it?
// function to read the database. it will print out the options
function printOptions($arg_1, $arg_2) {
$query = "SELECT * FROM style WHERE tag = '$arg_1' AND attrib = '$arg_2' ORDER BY val";
$result = mysql_db_query($GLOBALS["db"], $query, $GLOBALS["connection"]);
while($myrow = mysql_fetch_array($result)) {
if ($CSSArray["$arg_1"]["$arg_2"] == $myrow["val"]) {
print " <OPTION SELECTED VALUE=\"" . $myrow["val"] . "\">" . $myrow["val"] . "</OPTION>\n";
} else {
print " <OPTION VALUE=\"" . $myrow["val"] . "\">" . $myrow["val"] . "</OPTION>\n";
}
}
mysql_free_result($result);
}
How do I reference outside of my user defined function?
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Something that may mean less typing for you - you don't need quotes around variable names so:
can become
Mac
Code: Select all
$GLOBALSї"CSSArray"]ї"$arg_1"]ї"$arg_2"]Code: Select all
$GLOBALSї'CSSArray']ї$arg_1]ї$arg_2]