Solarpitch Posted February 28, 2008 Share Posted February 28, 2008 Hey Guys, I have the below piece of code which will basically print to screen 16 random numbers from a value of 0 - 9. Where you see... $value[2] = $num1; $value[6] = $num2; $value[8] = $num3; $value[10] = $num4; .. I am manipulating those array keys to insert my own 4 numbers into that array. What I am looking to do is when the 16 numbers are printed to screen, I want to highlight the above values on the screen. So I want to make the array values [2], [6], [8], [10] bold on the screen. Just wondering if this can be done. Here's the script <?php for ($i=0; $i<16; $i++) { $value[$i] = random_num(1); } $value[2] = $num1; $value[6] = $num2; $value[8] = $num3; $value[10] = $num4; echo "<strong Random Set:</strong> "; for ($i=0; $i<16; $i++) { echo $value[$i]." | "; } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted February 28, 2008 Share Posted February 28, 2008 <?php for ($i=0; $i<16; $i++) { $value[$i] = random_num(1); } $value[2] = $num1; $value[6] = $num2; $value[8] = $num3; $value[10] = $num4; echo "<strong Random Set:</strong> "; for ($i=0; $i<16; $i++) { if ($i % 2) { echo '<b>' . $value[$i]."</b> | "; } else { echo $value[$i]." | "; } } ?> Quote Link to comment Share on other sites More sharing options...
Solarpitch Posted February 28, 2008 Author Share Posted February 28, 2008 Ah I see, that makes every second value in the array bold. But I want to pick out only the 4 keys I listed. So would you modify it to something like... <?php for ($i=0; $i<16; $i++) { $value[$i] = random_num(1); } $value[2] = $num1; $value[6] = $num2; $value[8] = $num3; $value[10] = $num4; echo "<strong Random Set:</strong> "; for ($i=0; $i<16; $i++) { if ($value[$i] == 2) { // <-------------------------- echo '<b>' . $value[$i]."</b> | "; } else { echo $value[$i]." | "; } } echo "<br><br>"; ?> Quote Link to comment Share on other sites More sharing options...
trq Posted February 28, 2008 Share Posted February 28, 2008 for ($i=0; $i<16; $i++) { if ($i == 2 || $i == 6 ||$i == 8 ||$i == 10) { echo '<b>' . $value[$i]."</b> | "; } else { echo $value[$i]." | "; } } Quote Link to comment Share on other sites More sharing options...
Solarpitch Posted February 28, 2008 Author Share Posted February 28, 2008 Perfect! thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.