Reply to Re: Diferent numbers

Your name:

Reply:


Posted by Andrew @ Rockface on 06/24/05 16:16

In news:d9gp2c$j75$1@ss405.t-com.hr,
CyberDog <milan-SPAM-@cdnforum.com> wrote:
> Andrew @ Rockface wrote:
>> As each number is generated record it in an array, then check each
>> new number against the elements in the array.
>
> I would like to go with this
>
> Could you be so kind and write an example for me?
>
> is it something like this:
>
> while ($postition < $displayed_questions)
> {
> $question = array(
> $number => rand(1, $questions_in_database)
> )
> $number++
> }
>
> How to check if the number is used? While in a while?

I think the shuffle is the best way, unless you've got a massive amount of
questions :)

$questions_in_database = 10;
$questions = range(0,$questions_in_database);
shuffle($questions);
for ($c = 0; $c < 5; $c++) {
echo "RANDOM NUMBER =".$questions[$c]."<br>";
}

If you want to use the other method:

$questions_in_database = 5;
$questions = array();
for ($c = 0; $c < 5; $c++) {
$rnd = mt_rand(0,$questions_in_database);
if (! in_array($rnd, $questions)) {
$questions[] = $rnd;
}
}
echo "<pre>";print_r($questions);echo "</pre>";

--
Andrew @ Rockface
np: 1000 Suns - 5 [stopped]
www.rockface-records.co.uk

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация