CSS style print loop in multiple hrefs print files

I used the search function on this site and googled around, but could not find a definitive answer. If someone can point me in the right direction.

I set the links in the PHP print statement as follows:

print '<a href="'.$linkPath.'index.php" style="color:white">Home</a> | <a href="'.$linkPath.'scripts/login.php" style="color:white">Login</a>'. PHP_EOL;

This works for me, however the code shown is just a brief example, and I have a few more links.

Given the fact that this falls into the category of code redundancy with repetition

style="color:white"

I am looking for another solution.

Is it possible to use a loop in this situation, and if someone could give an example of how I can write it?

How to add a style to my links without explicitly specifying it for each link?

+4
2

. CSS,

print '<a href="'.$linkPath.'index.php" class="white">Home</a> | <a href="'.$linkPath.'scripts/login.php" class="white">Login</a>'. PHP_EOL;

CSS

.white{
     color:white;
 }

, CSS

#div>a{
    color:white;
}
+3

, css - , . class , , css.
CSS:

.white {
   color:white;
}

HTML:

<a href="index.php" class="white">Home</a>

, - , ? , for.

$links = array('Home' => 'index.php', 'login' => 'login.php');
$values = array_values($links);
$keys = array_keys($links);

for($i=0; $i<count($links); $i++) {
   print('<a href="' . $values[$i] . '" class="white">' . $keys[$i] . '</a> | ');
}

foreach ( ):

$links = array('Home' => 'index.php', 'login' => 'login.php');

foreach($links as $val => $link) {
   print('<a href="' . $link . '" class="white">' . $val . '</a> | ');
}
+2

All Articles