What is the best practice for outsourcing a PHP function to a separate file and including it in multiple pages?

To outsource a PHP function to a separate file and include it in multiple pages, you can create a separate PHP file containing the function and then include that file in the pages where you need to use the function. This helps in keeping your code organized and makes it easier to maintain and update the function in one central location.

// function.php
<?php
function myFunction() {
    // Function logic here
}
?>

// page1.php
<?php
include 'function.php';
myFunction();
?>

// page2.php
<?php
include 'function.php';
myFunction();
?>