I'm just wondering the difference between the following bits of code....
The first code has a function that takes three arguments. The second code has a function that takes no arguments but uses global variables.
Are there any benefits to either?
Passing arguments makes it clearer what your function works on. For example, one can guess from print_data($name, $surname, $message) that it prints a name, surname and message. Just looking at a print_data() call on the other hand makes it less clear what data is printed. Renaming the function to print_message_details() may help, but the reader still has to look into the function implementation to be sure of what are the message details. So, print_message($name, $surname, $message) would perhaps be an even better combination of function and variable names to make it clearer what the function does at a glance.
Global variables introduce a form of tight coupling between the variables in the function and the variables from the caller. If you rename a global variable, you have to change the implementation of all functions that use this global variable to reflect this renaming. If you pass arguments to a function instead, the function parameters can remain the same even if the variables passed as arguments are renamed.
Incidentally, use <?php instead of the short open tag version <? as the normal <?php tag is guaranteed to be available and does not have a potential conflict with XML's <?xml tag. You should also indent and place your code snippets in php bbcode tags.