Posted by yxod on 11/18/48 11:42
a simple word of advice: Do not use variable names that are the same
with php functions. If at any point you forget the $, strange things
will happen. check out rand().
and now that I am on it:
// function that generates a random number that does not exists in an
array
function get_random_number($random_array) {
$random_number=mt_rand(0,58);
if(is_array($random_array)&&in_array($random_number,$random_array)) {
return get_random_number($random_array); // recursiveness
} else {
return $random_number;
}
}
// fill the array
for($i=0; $i<13; $i++) {
$random_array[$i]=get_random_number($random_array);
}
// just to showcase
foreach($random_array as $number) {
echo $number.'<br>';
}
[Back to original message]
|