Bold a Select Result From an Array
Moderator: General Moderators
Bold a Select Result From an Array
I have an array of info, which is generated into html through a while loop. I want to bold a certain element if it corresponding variable is passed through the page....any help?
Here is a quick and simple solution, I hope it's what you wanted:
Code: Select all
<?php
/* Assuming the variable from somewhere else is called $variable */
// Transpose the keys and values
$arrayK = array_flip($array);
// Well, we make sure the variable passed exists in the array
if ( isset($arrayKї$variable]) )
{
// If so, we make it bold...
$arrayї$arrayKї$variable]] = '<b>'.$arrayї$arrayKї$variable]].'</b>';
}
unset($arrayK);
// And viola! print the array out! =)
foreach ( $array as $key => $value )
{
echo "$value<br />";
}
?>- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Not sure this is exactly what you are looking for but you could have an if loop within the while loop:
Mac
Code: Select all
if ($var == 'this') {
echo '<b>'.$var.'</b>';
} else {
echo $var;
}- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK