How can PHP developers use if-else statements to control access to specific links or functions based on user roles?

To control access to specific links or functions based on user roles, PHP developers can use if-else statements to check the role of the user and allow or restrict access accordingly. By checking the user's role before granting access to certain links or functions, developers can ensure that only authorized users can perform certain actions or view specific content.

$userRole = 'admin'; // Assume the user role is 'admin'

if ($userRole == 'admin') {
    // Allow access to specific links or functions for admins
    echo "Welcome, admin!";
} else {
    // Restrict access for non-admin users
    echo "You do not have permission to access this page.";
}