How would i set the output of a custom php function to a variable?
The function is:
function getRandomColor1() {
global $cols;
$num_cols = count($cols);
$rand = array_rand($cols);
$rand_col = $cols[$rand];
echo $rand_col;
unset($cols[$rand]);
}
How would i set getRandomColor1 equal to $RandomColor1?
I need it to be a variable so I can use it in css like:
#boxone1 {
height: 150px;
width: 150px;
background: <?=$RandomColor1?>;
float: left;
}
If its not possible to set it as a variable, how else could i put the output of the function into css?
OK, there are a number of answers that are pointing in the right direction, but to spell things out for you:
Your function needs to return the value that you want. Please read this link, since it is the answer to your question (thanks to egasimus for the link).
So something like this:
And then
Also,
<?=can lead to bugs and security issues if the server you’re working with doesn’t have the proper setting enabled (or decides to disable it later). It’s probably safer to just always use<?php echo.