Include() and Require() Function in PHP

[ad_1]

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:

  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

[ad_2]

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

GSTIN is 03EGRPS4248R1ZD.

Contact
Jassweb, Rai Chak, Punjab, India. 143518
Item added to cart.
0 items - 0.00