Not sure I understand. Like this? (Untested code)
PHP Code:
function make_link($this_page='') {
foreach(array('test', 'something', 'otherpage', 'whatever') as $page) {
if($this_page == $page) {
print '<div>' . $page . '</div>';
} else {
print '<div><a href="' . $page . '.php">' . $page . '</a></div>';
}
}
}
$this_page = 'something';
make_link($this_page);
Define $this_page in all your separate files, and put the function in a single file which is included into every separate file. Then you have to pass it the value of $this_page in some way. Here I'm sending it as a parameter to the function. You could also make it a global variable, or make a class to encapsulate it. There are different ways.
If you wanted to get tricky, you can fetch a script's own filename and do things with it. It's stored in the built-in variable $_SERVER['PHP_SELF'].
But you should be careful you're not doing something where you use the text in a link to dynamically access a bunch of files, or something like that. You should never use user input to do anything that might affect or access anything on your computer. Otherwise people will pass your script a link like "http://...../?page=../../../etc/passwd" and then you're in trouble.
I'm no PHP expert, there may be better ways of doing this.