What is the purpose of using a random avatar script in PHP?

Using a random avatar script in PHP allows for dynamically generating unique avatars for users on a website without requiring them to upload their own image. This can add a personalized touch to user profiles and enhance the overall user experience.

// Generate a random avatar image URL
$avatarOptions = [
    'avatar1.png',
    'avatar2.png',
    'avatar3.png',
    'avatar4.png',
];

$randomAvatar = $avatarOptions[array_rand($avatarOptions)];
$avatarUrl = 'https://example.com/avatars/' . $randomAvatar;

// Display the avatar image
echo '<img src="' . $avatarUrl . '" alt="Avatar">';