Assume that $myVar comes from the query string.
Then
if (!isset($_GET['myVar']))
$myVar = "default";
else
$myVar = $_GET['myVar'];
of course, you'll probably want to format or further validate $_GET['myVar'] before assigning it to $myVar, after which you'll use $myVar
The code only applies to that variable for any given script.
As such, it isnt really re-usable.
Sure, you could use the same code for multiple scripts using the same variable name, but then PHP's variable scope rules within functions will make that inconvenient, IMO.
You can place the function declaration anywhere in the script.
PHP isnt clientside, so generally you dont have to be concerned about the layout of the clientside page, i.e. HTML.