Hello,

I have a function which is registering a navigation menu

function register_menu($name, $displayname){
	if(!is_menu()){
		
		$menu['name'] = $name;
		$menu['displayname'] = $displayname;
		$registered = TRUE; //This should be global, so that is_menu() function can use it.
	}
}

And another function which checks if the menu is registered

function is_menu(){
	return $registered; //I need to get this from register_menu(). How ?
}

How can I use variables from one function in another function ?

Recommended Answers

All 2 Replies

Set global both sides:

function a()
{
        global $b;
        echo $b;
}

function c()
{
        global $b;
        $b = 'hello world';
        return $b;
}

c();
echo a();

It worked, thanks for quick answer!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.