How can mixing PHP and HTML in code impact the functionality and readability of a PHP script?

Mixing PHP and HTML in code can impact the functionality and readability of a PHP script by making it harder to maintain and debug. To solve this issue, it's recommended to separate PHP logic from HTML presentation by using PHP templating engines like Twig or Blade. This allows for cleaner code structure and easier collaboration between developers.

<?php
// Using a PHP templating engine like Twig
$loader = new \Twig\Loader\FilesystemLoader('path/to/templates');
$twig = new \Twig\Environment($loader);

// Render the template with data
echo $twig->render('template.html', ['variable' => $value]);
?>