I understand that good practice is to add the .js files in head of HTML.
My problem is that one of my .js files (or code+script) also has a beginning function, and it looks something like this (and all this is now in head):
<?php 
// Countdown timer
function timer($date, $id){ ?>
    <script>
        (function()
        { 
        // random stuff
        }
    </script>
// end function timer
<?php } ?>
How should I include/require or <script> src=" x "</script> this kind of file in the head of my HTML? I have hard time figuring out how to add this file in the proper way because of the beginning function.