Conditional inclusion of require and include-PHP source code

Source: Internet
Author: User
About require unconditional inclusion and include conditional inclusion about require unconditional inclusion and include conditional inclusion

// If the variable $ somgthing is true, it will contain the file somefile: 1 if ($ something) {2 include ("somefile "); 3} // regardless of the value of $ something, the following code will include the file somefile into the file: 1 if ($ something) {2 require ("somefile "); 3} // The Interesting example below fully demonstrates the differences between the two functions. 1 $ I = 1; 2 while ($ I <3) {3 require ("somefile. $ I "); 4 $ I ++; 5} // in this code, each loop contains the same file. Obviously, this is not the original intention of the programmer. from the code, we can see that this code will include different files in each loop. To complete this function, you must turn to the include () function: 1 $ I = 1; 2 while ($ I <3) {3 include ("somefile. $ I "); 4 $ I ++; 5}

The above is the content that require unconditionally contains and includes conditions. For more information, see PHP Chinese website (www.php1.cn )!

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.