Include vs Require

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.

Repost From : Here

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s