I want to teach you how to use variables in the include file without defining global variables. I am in 1. include (2.php) in php; in 2. define a doInit () function in php: functiondoInit () {$ UserUserID]; $ UserName $ _ SESSION [UserNmae];} I am at 1. php call instructions on how to use variables in the include file without defining global variables
This is the case.
I include (2.php) in 1. php );
Define a doInit () function in 2.php:
Function doInit (){
$ UserID = $ _ SESSION ['userid'];
$ UserName = $ _ SESSION ['usernmae'];
}
How can I use the $ UserID variable after I call the doInit () function in 1.php.
Do not define global variables.
Because many pages require content in doInit (), I plan to use the include method to write it in a page. You only need to implement this function.
------ Solution --------------------
If it is not a function, no!
------ Solution --------------------
PHP code
Function doInit () {$ UserID = $ _ SESSION ['userid']; $ UserName = $ _ SESSION ['usernmae']; return array ($ UserID, $ UserName );} $ ar = doInit (); echo $ ar [0]; echo $ ar [1];