Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use php require_once

Shulou Source: shulou.com Published: 2022-06-03 04:42:11 09月30日 Update

This article mainly explains "how to use php require_once", the explanation content in the article is simple and clear, easy to learn and understand, please follow the idea of Xiaobian slowly in-depth, together to study and learn "how to use php require_once"!

In php, the require_once statement is used to reference or include an external php file with the syntax "require_once(filename)" or "require_once 'filename'"; if the file specified by the statement has already been included, it will not be included again.

Operating environment of this tutorial: Windows 7 system, PHP7.1 version, DELL G3 computer

php require_once statement

require_once: Its role is the same as that of require, both reference or contain an external php file

Principle: When the php file containing require_once is executed, the external file specified by require_once will be included, and other code will form a new php file and start execution.

Syntax: "require_once(filename)" or "require_once 'filename'"

Note:

1. When the external included file has errors, it will also run incorrectly and terminate the operation.

When applying the require_once statement, it will first check whether the file to be included has already been included elsewhere in the program, and if so, it will not be included again.

Examples:

a.php

b.php

The result of running b.php is:

Hello

Note: The result is only a Hello output, indicating that the code in a.php has only been referenced once.

Thank you for reading, the above is the content of "how to use php require_once", after learning this article, I believe everyone has a deeper understanding of how to use php require_once, and the specific use needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Tags: Files statements packages learning code function content again results syntax operation principles places that is ideas situations tutorials articles more environment Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Microsoft Shulou Information Xiaomi MariaDB