The include statement includes and evaluates the specified file.
The include (or require) statement takes all the text/code/markup that exists in the specified file and copies it into the file that uses the include statement.
Including files is very useful when you want to include the same PHP, HTML, or text on multiple pages of a website.
Syntax
include 'filename';
or
require 'filename';
Example :
File my_include.php :
- <?php
- $sports1 = "football";
- $sports2 = "cricket";
- ?>
File myfile.php, which includes my_include.php :
- <?php
- include('my_include.php');
- echo "I prefer ". $sports1 ."
- than ". $sports2;
- ?>
Output
I prefer football than cricket
No comments:
Post a Comment