Karem
Karem

Reputation: 18103

PHP: Variable inside function use it outside function?

Im including almost every page in page_protect(); . I have made an variable for the userid, $userid, with the user´s id. So it will be much easier for me to get the id than calling SESSION_id each time on every page.

How can i use a variable inside that function outside the function?

Upvotes: 3

Views: 5820

Answers (1)

Bill Karwin
Bill Karwin

Reputation: 562368

function page_protect()
{
  global $id;
  $id = 1234;
}

page_protect();
echo $id;

Upvotes: 12

Related Questions