Tuesday, May 8, 2007

require vs include

php, to combine scripts from several files is by using statements include,
include_once,require and require_once.
So, what's the different between them ?

include vs include_once:
I will describe it by refering to the following example:

suppose we have a file one.php consist of code:
echo "Welcome to the jungle"

and we have a file two.php consist of code:
echo "By Tarzan"

then we like to combine one.php code into two.php
with code like this:

include("one.php");
include("one.php");
include("one.php");
echo "By Tarzan"

the result would be :

Welcome to the jungle
Welcome to the jungle
Welcome to the jungle
By Tarzan


if the we change the code like this:
include_once("one.php");
include_once("one.php");
include_once("one.php");
echo "By Tarzan"

the result would be :

Welcome to the jungle
By Tarzan

because 'include_once' would eliminate all of same values and would display
once, while 'include' would display all of them many times depend on how
many times one.php was repeated


require vs require_once:
the same as include vs include_once


include vs require:
viewed from the function of combining code, both of include and require is
same.
the different is when error occure, 'require' would not execute all of the
next codes , while 'include' would execute.


that's all :)

2 comments:

rizz said...

Wah aku ra mudeng
ning aku arep mampir wae...he he he
www.afadillah.blogspot.com

Unknown said...

numpang repost yaak