#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0

    What is the difference between include and include_once in php?


    Hello , Somebody please give me answer of this question. I am little confused about include and include_once in php.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,868
    Rep Power
    368
    its pretty simple, if you do:

    include(somefile.php);
    include(somefile.php);

    the script will include that file twice.

    if you did:

    include_once(somefile.php);
    include_once(somefile.php);

    then this file will only be included once
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    2
    Rep Power
    0
    Originally Posted by paulh1983
    its pretty simple, if you do:

    include(somefile.php);
    include(somefile.php);

    the script will include that file twice.

    if you did:

    include_once(somefile.php);
    include_once(somefile.php);

    then this file will only be included once
    Thanks for the reply Paulh1983, must say u are having good knowledge in php, read some of your replies.
  6. #4
  7. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,540
    Rep Power
    2337
    I fail to see how this information could not have been gleaned from reading the documentation for include and include_once. I mean, it's right in the first paragraph of the page for include_once (in fact, it's right in the function name itself!):

    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. As the name suggests, it will be included just once.
    If you want to be a software developer of any type, you must learn to read the documentation.

    Comments on this post

    • Jacques1 agrees
    • dmittner agrees
    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,868
    Rep Power
    368
    honestly though one might say that in this case no doc is needed as well as the function names are pretty "descriptive"
  10. #6
  11. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    23
    Rep Power
    0
    Te difference between include & include_once is that if the code from a file has already been included, it will not be included again with the use of include_once().
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,868
    Rep Power
    368
    Originally Posted by johnmacd
    Te difference between include & include_once is that if the code from a file has already been included, it will not be included again with the use of include_once().
    or you can just read the FIRST reply of this thread
  14. #8
  15. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,692
    Rep Power
    6351
    Ok now guys, enough quoting the dictionary. Thread closed.

    Comments on this post

    • paulh1983 agrees : lol a bit late innit? no one has replied to thread in 10 days ;)
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo