Home >> PHP >> What is the difference between include, include_once in PHP

What is the difference between include, include_once in PHP

1-include one file includes more times but include_once one file includes only one times.

2-The include_once() statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the include() statement, with the only difference being that if the code from a file has already been included, it will not be included again.

3-If file not found then show warning error but continue execution of the script.

Example-

I have three files
1-header.php
2-config.php
3-functions.php

functions.php

function test(){
    echo "Hello";
}

config.php

include_once('functions.php');
test();

header.php

include_once('functions.php');
include('config.php');

When open file header.php you will get error because config.php already includes functions.php

 

Post Your Comment

Next Questions
What is the difference between require and require_once
What is difference between include_once and require_once
What is difference between include and require
What is meant by urlencode and urldecode
How To Get the Uploaded File Information
Would I use print "$a dollars" or "{$a} dollars" to print out the amount of dollars
How do you pass a variable by value
How do I find out the number of parameters passed into function
How To Protect Special Characters in Query String
What is the difference between GET and POST
What are the different types of errors
If conditional statement
If else conditional statement
If else / else if conditional statement
Switch conditional statement
For loop
While loop
Do while loop
Foreach loop
Operators
Arithmatic operators
Assignment operators
Increment / Decrement Operators
Comparision Operators
Logical operators

Copyright ©2022 coderraj.com. All Rights Reserved.