Table of Contents
So what you can do is start a script tag just before your body tag and then write your PHP codes within it. For example, I want to write an array of names in the document. I would approach the below codes.
And it’s very simple so let’s see an example.
As you can see at the end of the file we have a script tag and within that tag, we have defined our JS variable using the value of the PHP variable.
And later we can use that JS variable within our JS file.
I hope I was able to help you with your problem. If you are still getting any errors, please don’t hesitate to comment, I will respond as soon as possible and help you with your error.