使用PHP / MySQL填充JavaScript数组

Although I have seen this question addressed in multiple posts not only here but on other forums, I am wanting some more basic information that pertains to the task I have at hand as each programmer has slightly different needs for this particular function.

For right now, I simply want to pull x-amount of data from my database (this is within my area of expertise as I have been working with these languages for a few years now...I also use mysqli extension) and then place that data in a JavaScript array.

At that point, I'll display the information in the JS array to suit a number of purposes I have in mind.

Writing standards-compliant code is important to me so I don't mind taking the time to learn the best way to accomplish these tasks.

I have seen mentions of JSON and other techniques. I'm not looking to anything dreadfully complex here, just populating the JS array from my DB.

Any and all help will be sincerely appreciated.

Populating any JS variable from PHP usually involves this kind of construct:

$myvar = array('hello world');

?>
<script type="text/javascript">
var myvar = <?php echo json_encode($myvar); ?>;
</script>