What are the differences between require, include, require_once and include_once in PHP?
Hello everyone! I've just started learning PHP and I can't figure out file inclusion. In textbooks and forums I keep encountering four constructs: require, include, require_once and include_once. At first glance they do the same thing — insert code from another file, but I feel there are important differences between them.
Here's an example of my code. I have a config.php file with database settings:
<?php
$host = 'localhost';
$user = 'root';
$pass = 'password';
?>
And a main file index.php where I'm trying to include it:
<?php
include 'config.php';
echo $host; // Works
?>
But when I change include to
No answers yet.
Log in to leave an answer