How can PHP developers optimize their code by separating HTML output from PHP logic?

PHP developers can optimize their code by separating HTML output from PHP logic using a templating engine like Twig or Blade. This separation helps to improve code readability, maintainability, and reusability. By keeping the presentation layer separate from the business logic, developers can focus on writing clean and efficient code.

```php
// Example of separating HTML output from PHP logic using Twig templating engine

// Include Twig autoloader
require_once 'vendor/autoload.php';

// Initialize Twig loader and environment
$loader = new \Twig\Loader\FilesystemLoader('templates');
$twig = new \Twig\Environment($loader);

// Define data to be passed to the template
$data = [
    'name' => 'John Doe',
    'age' => 30
];

// Render the template with the data
echo $twig->render('profile.twig', $data);
```

In this example, the PHP logic is kept separate from the HTML output by using Twig templating engine. The data is passed to the template for rendering, allowing for a clear separation of concerns.