What is the purpose of using the print function in this PHP code instead of directly writing HTML?

Using the print function in PHP allows for dynamic content generation and easier integration of PHP logic within HTML code. By using the print function, we can output variables, execute functions, and include conditional statements directly within the HTML markup. This makes the code more flexible and maintainable compared to directly writing static HTML.

<!DOCTYPE html>
<html>
<head>
    <title>Dynamic Content Example</title>
</head>
<body>
    <?php
    $name = "John";
    $age = 30;
    
    // Using print function to output dynamic content
    print("<p>Hello, my name is $name and I am $age years old.</p>");
    ?>
</body>
</html>