I realize that there have already been several threads on this type of question, but none that seemed to match mine. I have code that is correctly displaying a series of 6 numbers for a CSS background. Those 6 numbers are then stored into an array and the contents of that array are concatenated with a "#" sign in front of it. That, then is stored as another variable. Here:
$v = 0;
$array = array();
$tot;
$other0 = null;
$other1 = null;
$other2 = null;
$other3 = null;
$other4 = null;
$other5 = null;
$color;
for ($i=0;$i<6;$i++){ //loops 6 times to create 5 numbers
$tot = rand(0, 15);
if (($tot>9) && ($tot<16)){ //assigns 10 to "a" in hex
if ($tot == 10){
$tot = $other0;
$other0 = "a";
//echo $other0;
$array[$v++] = $other0;
}
elseif ($tot == 11){ //assigns 11 to "b" in hex
$tot = $other1;
$other1 = "b";
//echo $other1;
$array[$v++] = $other1;
}
elseif ($tot == 12){ //assigns 12 to "b" in hex
$tot = $other2;
$other2 = "c";
//echo $other2;
$array[$v++] = $other2;
}
elseif ($tot == 13){ //assigns 13 to "b" in hex
$tot = $other3;
$other3 = "d";
//echo $other3;
$array[$v++] = $other3;
}
elseif ($tot == 14){ //assigns 14 to "b" in hex
$tot = $other4;
$other4 = "e";
//echo $other4;
$array[$v++] = $other4;
}
elseif ($tot == 15) { //assigns 15 to "b" in hex
$tot = $other5;
$other5 = "f";
//echo $other5;
$array[$v++] = $other5;
}
}
else {
//echo $tot;
$array[$v++] = $tot; //if not, then just assign to array
}
}
$var = "";
$color = "";
for ($t=0; $t<6;$t++){
$var .= (string) $array[$t]; //displays the 6 numbers as one string
}
//var_dump($var); //for more visual reference, uncomment the var_dump
$color = "#" . $var;
echo $color;
That above is in PHP.
How do I get that variable to be displayed using CSS? Is it like (in the same PHP file): echo "<style>color:$color</style>";
or do I have to make a style.php for it to be referenced? If I do, how do I do that?
Many thanks!