FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


[php] array reference





-TomJ-
Hi all
I am working on a php script that will produce css items that will produce a gradient background colour from left to right. I have a working example which I am trying to convert to a class, so I can call it where I need it.

As parameters to this class I get the start colour and the stop colour. For each colour in the colour triplet, I calculate the difference, divide it by the necessarry width to get the gradient increase. This calculation is done in the __construct section of the class and ends with:
Code:
//Fill array with intermediate colour values
for ($i = 1; $i < $this->GradientWidth+1 ; $i += 1) {
   $arrColours[$i][red] =       round($this->Red1+($i * $this->RedShift),0);
   $arrColours[$i][green] =    round($this->Green1+($i * $this->GreenShift),0);
   $arrColours[$i][blue] =    round($this->Blue1+($i * $this->BlueShift),0);
   } /* End of For-loop */

Now, in a function I define in the class (which will a method of the object once it is instantiated), I want to extract the individual colours and combine them into CSS items:
Code:
function fnCreateCSS() {
for ($i = 1; $i < $this->GradientWidth+1 ; $i += 1) {
$this->MyCSSItems2 .= <<<EOT
#d$i {background-color:rgb($this->arrColours[$i][red],$this->arrColours[$i][green],$this->arrColours[$i][blue])}
<br>
EOT;
} /* End of for loop */
echo("echo2 <br>".$this->MyCSSItems1."<br>echo 3");

} /* End of fnCreateCSS */

But unfortunately, this coding of mine is not 100% correct: this is the output:
Code:
#d1 {background-color:rgb([1][red],[1][green],[1][blue])}
#d2 {background-color:rgb([2][red],[2][green],[2][blue])}
#d3 {background-color:rgb([3][red],[3][green],[3][blue])}

Where do I go wrong?
Is my coding to retrieve data from the array incorrect?
Is there an easy way to check if my routine to input data into the array has worked as intenden?
-TomJ-
I have found it.
No, I must be honest: I was pointed to my mistake in another forum.

This is how I filled the array originally:
Code:
//Fill array with intermediate colour values
for ($i = 1; $i < $this->GradientWidth+1 ; $i += 1) {
   $arrColours[$i][red] =       round($this->Red1+($i * $this->RedShift),0);
   $arrColours[$i][green] =    round($this->Green1+($i * $this->GreenShift),0);
   $arrColours[$i][blue] =    round($this->Blue1+($i * $this->BlueShift),0);
   } /* End of For-loop */

This fills the array at the __construct function level. I should have pointed to the array at class level, so not use $arrColours, but $this->arrColours.
Related topics
ASP.NET - Is this possible with frihost?
howto: Array ??
Awestys Flash Services
Highlighting Search Terms
PHP Image Questions
PHP Dropdown Selection
MySQL Question
php array() problem
displaying from array
The best php and html editor?
PHP Array, explode, count , access array problem.
Countries List - PHP Array
[PHP] Some beginner questions
i am having problems with this php code.... can someone help
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.