How can PHP variables be effectively passed and utilized in JavaScript functions for dynamic content loading?

When passing PHP variables to JavaScript functions for dynamic content loading, you can echo the PHP variable value directly into a JavaScript function call within your HTML code. This allows the JavaScript function to access the PHP variable value and use it for dynamic content loading.

<?php
$dynamic_content = "Hello, World!";
?>

<script>
function loadDynamicContent(content) {
  document.getElementById("dynamic-content").innerHTML = content;
}

// Call the function with the PHP variable value
loadDynamicContent('<?php echo $dynamic_content; ?>');
</script>

<div id="dynamic-content"></div>