What is the difference between using "require" within a function and outside of a function in PHP?

When using "require" within a function in PHP, the included file will only be included when the function is called. This can be useful if you only need the file's functionality within that specific function. On the other hand, using "require" outside of a function will include the file regardless of whether the function is called or not, potentially causing unnecessary overhead.

// Using require within a function
function myFunction() {
    require 'myfile.php';
    // Function code that uses functionality from myfile.php
}

// Using require outside of a function
require 'myfile.php';
// Code that may or may not call myFunction()