Page 1 of 1
Bold a Select Result From an Array
Posted: Mon Jun 03, 2002 4:15 pm
by bjwillis
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?
Posted: Mon Jun 03, 2002 4:22 pm
by jason
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 />";
}
?>
Posted: Mon Jun 03, 2002 4:22 pm
by twigletmac
Not sure this is exactly what you are looking for but you could have an if loop within the while loop:
Code: Select all
if ($var == 'this') {
echo '<b>'.$var.'</b>';
} else {
echo $var;
}
Mac
Posted: Mon Jun 03, 2002 4:23 pm
by jason
Just to point out the fundamental difference between twigletmac's code and mine. twigletmac would check on each loop of the array, whereas mine wouldn't.
That is assuming I understood all correctly.
Posted: Mon Jun 03, 2002 4:27 pm
by twigletmac
Well it was just a simple solution to a question without much info.
'spose it would depend on the size of the array whether it would make much difference.
Mac
Posted: Mon Jun 03, 2002 4:31 pm
by jason
Very true.
I just need to keep my post count higher than everyone elses.

Posted: Mon Jun 03, 2002 4:35 pm
by volka
I onced supposed a word-chain. It's amazing how it raises one's post-counter

(ok,ok this was spam)
Posted: Mon Jun 03, 2002 4:37 pm
by twigletmac
I think you're still fending off the competition fairly well

. (Although volka is trying really hard).
Now I guess we just have to wait for bjwillis to get back to see if we got anywhere close to answering his question

.
Mac
Posted: Mon Jun 03, 2002 4:40 pm
by jason
*hrm....should I manually adjust volka's count in the DB? Muhahahah! The power of DB access *
++$post_count;