I know this is a frequent question on Stack Overflow but I couldn’t find scenario where the PHP code is just above JS script in the same file. I guess ajax POST/GET won’t do the job in this case?
(...)
var ww = $(window).width();
</script>
<?php $ww = [data here] ?>
You will have to use POST/GET to send a JS variable to PHP, because PHP is processed by the server and JS is processed by the client.
I know this isn’t what you want to hear.