How can PHP be used to create an adaptive layout based on browser viewport size and orientation?

To create an adaptive layout based on browser viewport size and orientation, we can use PHP to detect the user's device screen size and adjust the layout accordingly. This can be achieved by using PHP to generate different CSS stylesheets or inline styles based on the viewport size or orientation.

<?php
if(isset($_SERVER['HTTP_USER_AGENT'])){
    $user_agent = $_SERVER['HTTP_USER_AGENT'];
    if(strpos($user_agent, 'Mobile') !== false){
        echo '<link rel="stylesheet" type="text/css" href="mobile_styles.css">';
    } else {
        echo '<link rel="stylesheet" type="text/css" href="desktop_styles.css">';
    }
}
?>