conditional colouring of  a variable value

ssalamee
ssalamee used Ask the Experts™
on
In PHP for example if $anumber>100, $anumber's colour should be red otherwise blue.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Ryan ChongSoftware Team Lead
Commented:
u can try:

$color = ($anumber>100)? "#FF0000" : "0000FF";

Open in new window

ref:
http://www.w3schools.com/html/html_colors.asp
Most Valuable Expert 2011
Top Expert 2016
Commented:
If you're new to PHP and want to learn the language, this article may be helpful.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html

Strictly speaking, variables have no color attribute.  They are just placeholder names that point to data locations in memory.  PHP is a server-side technology that creates strings of data and sends these strings to the client browser.  The browser renders these data strings, usually in the form of HTML, CSS and JavaScript.  Since the browser is responsible for visual rendering, PHP would, of necessity, need to interact with the browser via CSS in order to color some of the data red or blue.  Here is an example:
http://iconoun.com/demo/temp_ssalamee.php?a=99
http://iconoun.com/demo/temp_ssalamee.php?a=101
<?php // demo/temp_ssalamee.php

/**
 * http://www.experts-exchange.com/questions/28700436/conditional-colouring-of-a-variable-value.html
 */
error_reporting(E_ALL);

// SET THE DEFAULT COLOR
$c = 'blue';

// IF THERE IS A REQUEST, RESET THE COLOR
$a = !empty($_GET['a']) ? (int)$_GET['a'] : 0;
if ($a > 100) $c = 'red';

// SHOW THE VALUE OF VARIABLE "$a" USING THE CSS COLOR OF "$c"
echo PHP_EOL
. '<h1 style="color:'
. $c
. '">'
. $a
. '</h1>'
. PHP_EOL
;

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial