How can PHP beginners effectively implement an array to store and manage multiple URLs for dynamic redirection in scripts?
To store and manage multiple URLs for dynamic redirection in scripts, PHP beginners can effectively utilize an array. By creating an array to store the URLs and dynamically selecting the appropriate URL based on certain conditions, beginners can easily manage redirection logic in their scripts.
// Define an array of URLs for redirection
$redirect_urls = [
'home' => 'http://example.com/home',
'about' => 'http://example.com/about',
'contact' => 'http://example.com/contact'
];
// Get the desired URL key based on a condition
$redirect_key = 'home'; // Example condition to select a URL
// Redirect to the selected URL
header('Location: ' . $redirect_urls[$redirect_key]);
exit;