In one PHP file I have a variable named $difficulty.
I need to access this file in my javascript file, game.js. I have tried this inside my game.js file:
userDif = "<?php echo json_encode($difficulty); ?>";
console.log("Difficulty " + userDif);
However, this does not work, it just prints out "<?php echo json_encode($difficulty); ?>"
I have also tried just:
userDif = <?php echo json_encode($difficulty); ?>;
But then you get an error as it doesn't expect "<"
Any help would be greatly appreciated.
Edit: Apologies: This has already been answered! I was just searching for the wrong thing. Sorry!