Page 1 of 1

How do I reference outside of my user defined function?

Posted: Fri Sep 27, 2002 10:37 am
by lanlord
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);
}

Posted: Fri Sep 27, 2002 10:52 am
by jonsyd
How about:

$GLOBALS["CSSArray"]["$arg_1"]["$arg_2"]

J

duh

Posted: Fri Sep 27, 2002 10:56 am
by lanlord
Thanks, that's it! I bow before your greatness.

Posted: Sat Sep 28, 2002 4:53 am
by twigletmac
Something that may mean less typing for you - you don't need quotes around variable names so:

Code: Select all

$GLOBALS&#1111;"CSSArray"]&#1111;"$arg_1"]&#1111;"$arg_2"]
can become

Code: Select all

$GLOBALS&#1111;'CSSArray']&#1111;$arg_1]&#1111;$arg_2]
Mac

Posted: Sat Sep 28, 2002 10:51 am
by lanlord
I see that, Mac. Although I don't follow the theory perfectly, I'm trying to have it the same way always. In other words, if I use the double quotes with a string, I want to use them with the variables too.

Thanks for the tip tho, I'm always looking for just this sort of information. :D