Require and Include function in PHP; In this tutorial, we will describe to you the require and include the function of PHP with these function definitions, syntax, parameters, difference,s and examples.
The include() and require() functions are used to include code contained in one PHP file within another PHP file.
Include() and Require() Function in PHP
In PHP, Require and Include functions both are built-in functions of PHP. Both functions perform the same action.
- Include PHP Function
- Require PHP Function
Include PHP Function
Definition:- The include() function is built-in PHP function, which is used to include a file into the PHP script.
Note:- The PHP include() function, it will produce a warning error, without halt the execution of PHP script.
Syntax:-
The basic syntax of include function is the following:
include 'path/filename.php';
Example of include() function
The example of PHP include() function is the following:
<html>
<head>
//include file using include() function
<?php include 'path/head.php';?>
</head>
<body>
<h1>include() function Example</h1>
</body>
</html>
Require PHP Function
Definition:- The require() function is built-in PHP function, which is used to include a file into the PHP script. :-
Note:- The PHP require() function, it will produce a fatal error and halt the execution of php script.
Syntax:-
The basic syntax of the require function is the following:
require 'path/filename.php';
Example of Require() function
The example of PHP require() function is the following:
<html>
<head>
//require file using require() function
<?php require 'path/head.php';?>
</head>
<body>
<h1>include() function Example</h1>
</body>
</html>
Question:- What is the difference between include and require in PHP?
Answer:- In PHP, Require and Include function both are the built-in function of PHP. Both functions perform the same action. The main difference is that the include() function produces a warning, without halt execution of PHP script, while the require() function produces a warning and a fatal error i.e. the script will halt the execution.
Recommended PHP Tutorial:
- Autocomplete Search Box in PHP MySQL
- Compare Arrays PHP | PHP array_diff() Function
- Get, Write, Read, Load, JSON File from Url PHP
- Functions: Remove First Character From String PHP
- Remove Specific/Special Characters From String In PHP
- How to Replace First and Last Character From String PHP
- Reverse String in PHP
- Array Push, POP PHP | PHP Array Tutorial
- PHP Search Multidimensional Array By key, value and return key
- json_encode()- Convert Array To JSON | Object To JSON PHP
- PHP remove duplicates from multidimensional array
- PHP Remove Duplicate Elements or Values from Array PHP
- Get Highest Value in Multidimensional Array PHP
- PHP Get Min or Minimum Value in Array