Forum Moderators: coopster

Message Too Old, No Replies

nesting a function inside another

cant make menu script work

         

hafnius

10:39 pm on Jul 17, 2003 (gmt 0)

10+ Year Member



Hi all

I have a clever menuscript in php that i cant quite get to work. it is basically two functions, but i cant get the first to call the next function. the idea for this is to reuse the menu() with the different menuitems.

first function:


function menu() {
$namecount = count($name); for ($i = 0; $i < $namecount; $i++) { if ($url[$i] == $file)
{ echo ("<li><a class=\"now\" title=\"$title[$i]\">$name[$i]</a></li>"); }
else { echo ("<li><a href=\"$url[$i]\" title=\"$title[$i]\">$name[$i]</a></li>"); } }
print"</ul>\n";

and the main function


function hvem() {
echo "<h3>Hvem</h3><div id='sidenav'><ul>\n";

$name = array ( "foo");
$url = array ( "/index.php");
$title = array ( "foo_title");

$file = $_SERVER['PHP_SELF'];
menu();}

What this does is to check whether the file being called is identical with the url and then higlighting it if this is the case.

But how to make the "menu()" get executed? i have tried many ways but nothing seems to work for this newbie. it doesnt throw a parse error. any suggestions? i hope i am not way off.

Thanx in advance
Hafnius

Birdman

11:07 pm on Jul 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello,

You may need to declare your variables as global.

function hvem() {
global $name,$url,$title,$file;
...etc.

hafnius

11:20 pm on Jul 17, 2003 (gmt 0)

10+ Year Member



Hi Birdman

Thanks for the reply, Birdman

You may need to declare your variables as global.

i still just get the headline on the menu, not the menuitems in the array:

echo "<h3>Hvem</h3><div id='sidenav'><ul>\n";

i feel this shoul be pretty straight forward but i cant seem to cut it.

Should i post a dummy to play with?

Regards
Hafnius

hafnius

11:38 pm on Jul 17, 2003 (gmt 0)

10+ Year Member



Hi Birdman

Sorry for my disbelief in your solution - it was correct. both the hvem() and the menu() had to have the variables declared as globals.

Thanks very much - have a nice weekend when it comes your way!

Regards
Hafnius