In the situation where index page is the root for every request. And based on URL different page are served.
For now we use same name for CSS file as for page to be served.
But this fails where we want to use same CSS for a group of page or we don't want a special CSS for a page common CSS is sufficient
Also array is suggest a solution but it seem to be unmanageable when site pages increase
A LUT would be the fastest way, although I think you need to seriously re-architect your app.
Anyway on your index page you have some variable $pageName that says which page you want to load. The you can do something like this.
$myPages = array(
"somePage" => array("style_base.css", "custom_style1.css"),
"otherPage" => array("style_base.css", "awesome_style.css")
// more pages here
);
foreach( $myPages[$pageName] as $pageStyleSheet ) {
echo '<link href="' . $pageStyleSheet . '" rel="stylesheet" type="text/css">' . PHP_EOL;
}
Just so you know this is super hacky and if I had to maintain your app, I would probably want to kill you. BUT it is the fastest way based on the architecture you described.
Another idea, but if you keep the stylesheet for every page based on the page name and use @include for the sheets you want to reuse. So for somePage.css you could have
@include('otherPage.css')
That way you can keep reflecting off the page name, but still reuse styles.
@Champ - You can use a CSS file for the whole web site - use classes etc. These files are very small in comparison to an image. We are talking ASCII and tens of kilobytes (at most) - and that can be cached!
EDIT
Use that extra server load instead of PHP to determine the CSS stuff for better things