Jump to content

Adding to an array


b1011

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/62540-adding-to-an-array/#findComment-311294
Share on other sites

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.