You are here: Re: Diferent numbers « All PHP « IT news, forums, messages
Re: Diferent numbers

Posted by CyberDog on 06/24/05 17:52

Andrew @ Rockface wrote:
> 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>";

You helped a lot, thank you! :)

 

Navigation:

[Reply to this 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

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