require() function in php
0 2009
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>"; ?>
Share:
Comments
Waiting for your comments