phpfunctionglobal

How to define global functions in PHP


How can I define a global function which would be accessible from any page?


Solution

  • In file include.php:

    function myGlobalFunction() {
        // Do something
    }
    

    Then in every page you want to use it:

    include 'include.php';
    myGlobalFunction();