coder9 Posted July 17, 2008 Share Posted July 17, 2008 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. Quote Link to comment Share on other sites More sharing options...
unkwntech Posted July 17, 2008 Share Posted July 17, 2008 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++; } Quote Link to comment Share on other sites More sharing options...
coder9 Posted July 17, 2008 Author Share Posted July 17, 2008 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! Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted July 17, 2008 Share Posted July 17, 2008 Here's an even shorter solution using the array_fill() function: <?php $tmbakcolor = array_fill(1,100,'#FF0000'); ?> Ken Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.