require() function in php || PHP Functions

require() function in php

Last Updated by Lalita 02-Mar-20

0 375


require() function works same as include() function works. By using this function you can get the values/data of the that file which is mentioned in require() function.

The difference is only that if file path is not properly mentioned then this require() function throws a fatal error and halts/stops the execution of the file. 

Mostly, this function is required when you use all the data of a file or section at many places in other files.

How to use: require() function in PHP

=> Remember that this function can be used as a statement. Like below:-

require "filename";

=> It is not necessary to use ()braces with the require statement. 

=> Both work same.


<?php
require "test1.php";
?>

require() function in php


<?php
require "testing_file.php";

echo "<p>hi</p>";
?>

require() function in php


<?php
require("test1.php");

echo "<p>hi</p>";
?>

require() function in php


Share:


Leave a Reply


Comments
    Waiting for your comments