b1011 Posted July 30, 2007 Share Posted July 30, 2007 You know how you can do this: array("#ff0000","#ff8800","#0022ff","#33ff33") Well how could i set it up so that in a while statement it adds to the array? And if its possible how can i make it add a random color (#ff0000 etc.); Any ideas? Did i explain good enough? Quote Link to comment Share on other sites More sharing options...
DeepakJ Posted July 30, 2007 Share Posted July 30, 2007 Well there has to be some sort of pattern to the array. And yes, if there is you can make it into a while loop. Quote Link to comment Share on other sites More sharing options...
Grodo Posted July 30, 2007 Share Posted July 30, 2007 <?php $colors = array('#ffff23', '#faaf23', '#ff3323', '#f99f23', '#ff8823', '#fff773'); ?> Then you call it by $colors[position] the position is the spot ur value is in so if u want #ffff23 it would be $colors[0] Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 30, 2007 Share Posted July 30, 2007 Adding to the array is as simple as doing $array[] = $var. There's a few examples in the user comments on the php site for the mt_rand function for random hex codes. Ive used one for this example: <?php $array = array("#ff0000","#ff8800","#0022ff","#33ff33"); for($x=0;$x<9;$x++){ //thanks to zolaar at nothanks dot com - taken from the a comment on http://uk3.php.net/mt_rand $num = mt_rand ( 0, 0xffffff ); $output = sprintf ( "%06x" , $num ); $array[] = '#'.$output; } print_r($array); ?> 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.