What i want is create a function that automatically generate the link with or without parameters from an array. I have created a function to generate the link but i don't know how I can also generate the link with the parameters.
$path = array(
'HOME_PATH' => '/home',
'PROFILE_PATH' => '/profile/$id',
'POST_PATH' => '/post/$id/$slug',
);
generateLink($path);
function generateLink($path) {
foreach( $path as $constant => $path )
{
if(!defined( strtoupper($constant) ) )
{
define( strtoupper($constant), 'localhost/blog' . $path);
}
}
}
Html
<a href="<?php echo generateLink(POST_PATH); ?>">Home Page</a>
<a href="<?php echo generateLink(POST_PATH, $id, $slug); ?>">Post Details</a>
<a href="<?php echo generateLink(PROFILE_PATH, $id); ?>">Profile</a>