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]." | "; } ?> Link to comment https://forums.phpfreaks.com/topic/93487-highlighting-a-value-in-an-array/ 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]." | "; } } ?> Link to comment https://forums.phpfreaks.com/topic/93487-highlighting-a-value-in-an-array/#findComment-478955 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>"; ?> Link to comment https://forums.phpfreaks.com/topic/93487-highlighting-a-value-in-an-array/#findComment-478963 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]." | "; } } Link to comment https://forums.phpfreaks.com/topic/93487-highlighting-a-value-in-an-array/#findComment-478964 Share on other sites More sharing options...
Solarpitch Posted February 28, 2008 Author Share Posted February 28, 2008 Perfect! thanks. Link to comment https://forums.phpfreaks.com/topic/93487-highlighting-a-value-in-an-array/#findComment-478967 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.