You can – as the accepted answer indicates – generate entire javascript files with PHP. But if you are just trying to access some limited dynamic content, this is often overkill. If you are just trying to access a few variables that need to be PHP generated, inline javascript works fine. Add this to your HTML's head:
<script type="text/javascript">
<?php if( $condition == true ) : ?>
var variable1 = <?php $var1 ?>,
variable2 = <?php $var2 ?>;
<?php else: ?>
var variable1 = <?php $var1Alt ?>,
variable2 = <?php $var2Alt ?>;
<?php endif; ?>
</script>
Just make sure you add this before any linked scripts depend on these variables.