search
HomeBackend DevelopmentPHP TutorialPHP uses custom function library include() and require() function usage detailed explanation

Code reuse
Improve development efficiency and reduce costs by reusing existing code
include() and require() functions. [Interview Frequently Asked Questions]
require() imports a file during preprocessing, like pasting the file into where the function is used.

include() is almost equivalent to require(). The difference is that it is included when the script is executed. When the processing fails, include() generates a warning while require() results in a fatal error.

include_once( ) and require_once( ) functions
The two functions are included and included during script execution. Run the specified file. Similar to the include() statement and require(), the only difference is that if the code in the file is already included, it will not be included again, but only once. These two functions should be used when the same file may be included more than once during script execution, and you want to ensure that it is only included once to avoid problems with function redefinition, variable reassignment, etc.

<?php
    require &#39;config.php&#39;;           //使用require语句包含并执行config.php文件
    if ($condition)                     //在流程控制中使用include语句
        include &#39;file.txt&#39;;             //使用include语句包含并执行file.txt文件
    else                                    //条件不成立则包含下面的文件
        include (&#39;other.php&#39;);      //使用include语句包含并执行other.php文件
    require (&#39;somefile.txt&#39;);       //使用require语句包含并执行somefile.txt文件

Example:

<?php
error_reporting(0);  	
require "function.inc.php";
	if($a=="a") include "demo.txt";
	else include "demo2.html";
	one();
	two();
	three();

function.inc.php contains The purple one:

<?php
	function one(){
		echo "1111111<br>";
	}
	function two(){
		echo "222222<br>";
	}
	function three(){
		echo "333333<br>";
	}

The html contains the purple one:

bbbbbbbbbbbbbbbbbbbb

Output the purple one:

bbbbbbbbbbbbbbbbbbbb
1111111
222222
333333

## At the end of last year, the unsatisfactory .net homework and school competition ended. It's just unsatisfactory. It's far away from expectations, but it's still manageable. I relaxed a bit the day before yesterday and yesterday. Today, I spent another day sorting out some of the knowledge points on PHP functions. Mainly because of the half-way distance. Yue, I forgot too much. Then again, I didn’t learn it well the first time. As expected, just watching the video is not enough. I expect to be able to figure out anonymous functions and closures before 7 o’clock. Finished, I’m working on linux in the evening. I’m so happy when I think that I still have a day of my own time tomorrow~~Tomorrow should be linux+state compression

Looking back on the past year, it’s really fulfilling The overall state was so bad that I suddenly remembered that there was bestcoder at night, so I adjusted my state~~go~go~go~

When I went out on the ninth floor on the 30th, I was so scared. No, when I saw the teacher talking to other teachers at the door, I just moved out step by step. I didn’t want to feel this way again. T^T, my senior actually praised me when I went to bed (⊙﹏⊙)b What's so exciting about finishing ninth? I'm next year, no, this year! People who are looking for a job T^T, the content I have learned right now is not enough, not to mention that I can’t let go of the competition at all, and I obviously feel that I don’t have enough time.

Anyway, please keep working hard in the new year! !

The above is the detailed content of PHP uses custom function library include() and require() function usage detailed explanation. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
如何在Netflix中快速设置自定义头像如何在Netflix中快速设置自定义头像Feb 19, 2024 pm 06:33 PM

Netflix上的头像是你流媒体身份的可视化代表。用户可以超越默认的头像来展示自己的个性。继续阅读这篇文章,了解如何在Netflix应用程序中设置自定义个人资料图片。如何在Netflix中快速设置自定义头像在Netflix中,没有内置功能来设置个人资料图片。不过,您可以通过在浏览器上安装Netflix扩展来实现此目的。首先,在浏览器上安装Netflix扩展的自定义个人资料图片。你可以在Chrome商店买到它。安装扩展后,在浏览器上打开Netflix并登录您的帐户。导航至右上角的个人资料,然后单击

Win11如何自定义背景图片Win11如何自定义背景图片Jun 30, 2023 pm 08:45 PM

Win11如何自定义背景图片?在最新发布的win11系统中,里面有许多的自定义功能,但是很多小伙伴不知道应该如何使用这些功能。就有小伙伴觉得背景图片比较单调,想要自定义背景图,但是不知道如何操作自定义背景图,如果你不知道如何定义背景图片,小编下面整理了Win11自定义背景图片步骤,感兴趣的话一起往下看看把!Win11自定义背景图片步骤1、点击桌面win按钮,在弹出的菜单中点击设置,如图所示。2、进入设置菜单,点击个性化,如图所示。3、进入个性化,点击背景,如图所示。4、进入背景设置,点击浏览图片

vue3+vite:src使用require动态导入图片报错怎么解决vue3+vite:src使用require动态导入图片报错怎么解决May 21, 2023 pm 03:16 PM

vue3+vite:src使用require动态导入图片报错和解决方法vue3+vite动态的导入多张图片vue3如果使用的是typescript开发,就会出现require引入图片报错,requireisnotdefined不能像使用vue2这样imgUrl:require(&rsquo;&hellip;/assets/test.png&rsquo;)导入,是因为typescript不支持require所以用import导入,下面介绍如何解决:使用awaitimport

如何在Python中创建和自定义Venn图?如何在Python中创建和自定义Venn图?Sep 14, 2023 pm 02:37 PM

维恩图是用来表示集合之间关系的图。要创建维恩图,我们将使用matplotlib。Matplotlib是一个在Python中常用的数据可视化库,用于创建交互式的图表和图形。它也用于制作交互式的图像和图表。Matplotlib提供了许多函数来自定义图表和图形。在本教程中,我们将举例说明三个示例来自定义Venn图。Example的中文翻译为:示例这是一个创建两个维恩图交集的简单示例;首先,我们导入了必要的库并导入了venns。然后我们将数据集创建为Python集,之后,我们使用“venn2()”函数创

如何在CakePHP中创建自定义分页?如何在CakePHP中创建自定义分页?Jun 04, 2023 am 08:32 AM

CakePHP是一个强大的PHP框架,为开发人员提供了很多有用的工具和功能。其中之一是分页,它可以帮助我们将大量数据分成几页,从而简化浏览和操作。默认情况下,CakePHP提供了一些基本的分页方法,但有时你可能需要创建一些自定义的分页方法。这篇文章将向您展示如何在CakePHP中创建自定义分页。步骤1:创建自定义分页类首先,我们需要创建一个自定义分页类。这个

Eclipse中自定义快捷键设置的方法Eclipse中自定义快捷键设置的方法Jan 28, 2024 am 10:01 AM

如何在Eclipse中自定义快捷键设置?作为一名开发人员,在使用Eclipse进行编码时,熟练掌握快捷键是提高效率的关键之一。Eclipse作为一款强大的集成开发环境,不仅提供了许多默认的快捷键,还允许用户根据自己的偏好进行个性化的定制。本文将介绍如何在Eclipse中自定义快捷键设置,并给出具体的代码示例。打开Eclipse首先,打开Eclipse,并进入

Vue3中的render函数:自定义渲染函数Vue3中的render函数:自定义渲染函数Jun 18, 2023 pm 06:43 PM

Vue是一款流行的JavaScript框架,它提供了许多方便的功能和API以帮助开发者构建交互式的前端应用程序。随着Vue3的发布,render函数成为了一个重要的更新。本文将介绍Vue3中render函数的概念、用途和如何使用它自定义渲染函数。什么是render函数在Vue中,template是最常用的渲染方式,但是在Vue3中,可以使用另外一种方式:r

如何在装有 iOS 17 的 iPhone 上的 Apple Music 中启用和自定义交叉淡入淡出如何在装有 iOS 17 的 iPhone 上的 Apple Music 中启用和自定义交叉淡入淡出Jun 28, 2023 pm 12:14 PM

适用于iPhone的iOS17更新为AppleMusic带来了一些重大变化。这包括在播放列表中与其他用户协作,在使用CarPlay时从不同设备启动音乐播放等。这些新功能之一是能够在AppleMusic中使用交叉淡入淡出。这将允许您在曲目之间无缝过渡,这在收听多个曲目时是一个很棒的功能。交叉淡入淡出有助于改善整体聆听体验,确保您在音轨更改时不会受到惊吓或退出体验。因此,如果您想充分利用这项新功能,以下是在iPhone上使用它的方法。如何為AppleMusic啟用和自定Crossfade您需要最新的

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),