Jump to content

[SOLVED] How to make this code shorter using looping the array?


coder9

Recommended Posts

Ok guys

 

I have this codes below which has the variable name '$tmpbackcolor1' from 1 to 100, which is very annoying because it's too long.

 

$tmpbakcolor1="#FF0000";
$tmpbakcolor2="#FF0000";
$tmpbakcolor3="#FF0000";
$tmpbakcolor4="#FF0000";
$tmpbakcolor5="#FF0000";

...

$tmpbakcolor99="#FF0000";
$tmpbakcolor100="#FF0000";

 

Now how do i convert it into array variables and just loop it to make it shorter.

 

this easy for coder who is very familiar with array and some loop functions.

 

Your help is a big enhancement to my codes.

therefore thank you in advance.

 

 

I would make $tmpbakcolor into an array, then use a while loop to step through and assign each variable.

$tmpbakcolor = array();
$i=1;
while($i<100)
{
    $tmpbakcolor[$i] = "#FF0000";
    $i++;
}

 

Thanks unkwntech, your da best I LOVE YOU!  ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.