How to use variables in the include file without defining global variables

Source: Internet
Author: User
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];

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.