What are the best practices for creating dynamic links in PHP, such as linking to specific profiles based on user IDs stored in an array?

When creating dynamic links in PHP to specific profiles based on user IDs stored in an array, it is best practice to use a foreach loop to iterate through the array and generate the links dynamically. This ensures that each user's profile is linked correctly without hardcoding individual links.

<?php
$users = array(
    1 => 'John',
    2 => 'Jane',
    3 => 'Alice'
);

foreach ($users as $userId => $username) {
    echo "<a href='profile.php?id=$userId'>$username's Profile</a><br>";
}
?>