Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: Variable inside function use it outside function?

Tags:

php

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?

like image 839
Karem Avatar asked Apr 08 '26 07:04

Karem


1 Answers

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

page_protect();
echo $id;
like image 166
Bill Karwin Avatar answered Apr 09 '26 22:04

Bill Karwin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!