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.

 

 

Link to comment
Share on other sites

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!  ;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.