No, storing PHP variables in the head is not the proper way to do it. In fact, when you do this, your variables are NOT stored inside the head, PHP is server side, HTML/CSS/Javascript are client side.
You want to store your variables before there is even any HTML that is outputted.
However, if you do something like this :
<head>
<title>PHP Head Test</title>
<?php $data; ?>
</head>
It's not actually doing anything, if you wanted to display it, you would use echo. This code does absolutely nothing except declare $data if it wasn't declared before-hand.
Generally, you should have most of your PHP code out of your HTML file, they should be in completely different files and the PHP code should include the HTML file. In this case, the PHP code that you put in the HTML file will have access to all PHP variables that were available in the file where it was included.