Include files in PHP. Include and require code examples open

Include files in PHP. Include and require code examples

Approved. Code works!
This is exactly the working code that is verified by the moderator or site administrators

The include statement includes an external file with php code into the program. So, for example, let’s define the hello.php file.

Let’s create a file for an example, call it hello.php and add the code below:

$age = 24;

Now let’s attach this file to our main one and use the $age variable:

include "hello.php";//include our file
 
$name = "Ben";
echo $name . '=' . $age;
When the file is not found include will issue an error, require will issue a warning but execute the code.
require "hello.php";//include our file

include once, require once

include the file only once:

include once "hello.php";
require once "hello.php";

In large applications, the number of included files can be quite large. However, the built-in function spl_autoload_register()

0

More

Leave a Reply

Your email address will not be published. Required fields are marked *

How many?: 22 + 22

lil-code© | 2022 - 2024
Go Top
Authorization
*
*
Registration
*
*
*
*
Password generation