How can PHP developers effectively handle multiple placeholders for navigation links in a template system?

When dealing with multiple placeholders for navigation links in a template system, PHP developers can effectively handle them by using an associative array to store the links and their corresponding placeholders. By looping through this array and replacing the placeholders with the actual links in the template, developers can dynamically generate navigation menus without hardcoding each link.

// Define an associative array with placeholders as keys and links as values
$navigationLinks = array(
    'home' => 'index.php',
    'about' => 'about.php',
    'contact' => 'contact.php'
);

// Template with placeholders for navigation links
$template = '<nav>
                <ul>
                    <li><a href="{home}">Home</a></li>
                    <li><a href="{about}">About</a></li>
                    <li><a href="{contact}">Contact</a></li>
                </ul>
            </nav>';

// Loop through the array and replace the placeholders with actual links
foreach ($navigationLinks as $placeholder => $link) {
    $template = str_replace("{" . $placeholder . "}", $link, $template);
}

// Output the template with replaced navigation links
echo $template;