Include() and Require() Function in PHP

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:



//include file using include() function





include() function Example

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:



//require file using require() function





include() function Example

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:

  1. Autocomplete Search Box in PHP MySQL
  2. Compare Arrays PHP | PHP array_diff() Function
  3. Get, Write, Read, Load, JSON File from Url PHP
  4. Functions: Remove First Character From String PHP
  5. Remove Specific/Special Characters From String In PHP
  6. How to Replace First and Last Character From String PHP
  7. Reverse String in PHP
  8. Array Push, POP PHP | PHP Array Tutorial
  9. PHP Search Multidimensional Array By key, value and return key
  10. json_encode()- Convert Array To JSON | Object To JSON PHP
  11. PHP remove duplicates from multidimensional array
  12. PHP Remove Duplicate Elements or Values from Array PHP
  13. Get Highest Value in Multidimensional Array PHP
  14. PHP Get Min or Minimum Value in Array

Images mentioned above related to PHP are either copyright property of respective image owners.

Rabins Sharma Lamichhane

Rabins Sharma Lamichhane is senior ICT professional who talks about #it, #cloud, #servers, #software, and #innovation. Rabins is also the first initiator of Digital Nepal. Facebook: rabinsxp Instagram: rabinsxp

Leave a Reply

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