How can the code be modified to incorporate CSS classes for styling the elements instead of inline styling?

To incorporate CSS classes for styling the elements instead of inline styling, we can add a class attribute to each HTML element and define the styles in an external CSS file. This helps in separating the content from the presentation, making the code more maintainable and easier to update in the future.

<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<?php
$names = array("Alice", "Bob", "Charlie");

echo "<ul>";
foreach ($names as $name) {
  echo "<li class='name'>$name</li>";
}
echo "</ul>";
?>
</body>
</html>
```

styles.css:
```css
.name {
  color: blue;
  font-weight: bold;
}