require() function in php || PHP Functions
×


require() function in php

1827

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";
?>


<?php
require "testing_file.php";

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


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

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




Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments