I need help implement a Javascript code into the PHP file

Just make sure that all JS is inside the <script> tags and you can use PHP anywhere as long as it’s .php file and it’s inside the <?php and ?>. Simple as that!

It’s kind of ugly and it’s far from super readable but that’s the way to do it.


<?php
$php_code="My PHP is here!!";

/*Close PHP*/ ?>

<script> //All JS inside the <script> tags

    var jsCode="All my JavaScript here!!";

    <?php
    if( $i_can_also_use_php_here ) { ?>

        var jsAgain = 'Just JS and PHP back and forth!!'; <?php 

    } ?> // "}" is closing PHP if statement

</script> 

<?php //Open PHP, no more JS, <script> tag is closed

$continue_php = 'Let's continue this beast!!'; ?>