pxxb Posted September 26, 2013 Share Posted September 26, 2013 I am trying to display all the contents of the array but I want to make "Chicken" in red font. How can I do this? I am new to Php. TY $animals = array("goat", "pig", "chicken","lion); //arrayforeach ($animals as $word){ //print all of arrayecho $word; Quote Link to comment https://forums.phpfreaks.com/topic/282447-help-changing-array-to-different-color/ Share on other sites More sharing options...
mac_gyver Posted September 26, 2013 Share Posted September 26, 2013 you would declare a css class to use the color red. then when you are outputting the values form the array, for the value you want, you would surround it with a <span></span> tag with the css class you have declared. Quote Link to comment https://forums.phpfreaks.com/topic/282447-help-changing-array-to-different-color/#findComment-1451236 Share on other sites More sharing options...
pxxb Posted September 26, 2013 Author Share Posted September 26, 2013 you would declare a css class to use the color red. then when you are outputting the values form the array, for the value you want, you would surround it with a <span></span> tag with the css class you have declared. So would I do something like: foreach ($animals as $word){ '<span class ="red" >' $animals[2] '</span>' echo $word; That would make only chicken red when printing entire array? Quote Link to comment https://forums.phpfreaks.com/topic/282447-help-changing-array-to-different-color/#findComment-1451237 Share on other sites More sharing options...
Solution Zane Posted September 26, 2013 Solution Share Posted September 26, 2013 (edited) foreach ($animals as $word){ if($word == "chicken") echo '' $animals[2] ''; else echo $word; } Edited September 26, 2013 by Zane Quote Link to comment https://forums.phpfreaks.com/topic/282447-help-changing-array-to-different-color/#findComment-1451240 Share on other sites More sharing options...
pxxb Posted September 26, 2013 Author Share Posted September 26, 2013 foreach ($animals as $word){ if($word == "chicken") echo '<span class ="red" >' $animals[2] '</span>'; else echo $word; } thank you. Quote Link to comment https://forums.phpfreaks.com/topic/282447-help-changing-array-to-different-color/#findComment-1451241 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.