You can put functions anywhere in the code. So they can be at the beginning, middle or end.
You can also put them in a completely different file and Include or Import them as well.
You can also put them in a completely different file and Include or Import them as well.