What is the difference between include, require, include_once and require_once in PHP?
Hello everyone! I just started learning PHP and I can't understand the difference between these four constructs for including files. They all seem to do the same thing — insert code from another file.
\n\nI have a file config.php with database settings:
<?php\n$host = 'localhost';\n$db = 'mydb';\n$user = 'root';\n$pass = '';\n?>\n\nAnd I include it in index.php in different ways:
<?php\ninclude 'config.php';\n// or\nrequire 'config.php';\n// or\ninclude_once 'config.php';\n// or\nrequire_once 'config.php';\n?>\n\nAll four options work, and I can see the variables from config.php. So what's the difference? When should I use which?
\n\nAlso, I noticed something strange: if I twice
No answers yet.
Log in to leave an answer
Blogs