Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> shuffle()
johno
post
Post #1





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 8.06.2002
Skąd: z Krakowowa

Ostrzeżenie: (0%)
-----


Czemu to nie dziala?(IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif) (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif)
Kod
<?

$tab = array("adres1", "adres2", "adres3", "adres4", "adres5", "adres6", "adres7", "adres8");

shuffle($tab);

echo $tab[0];

?>

przy kazdym odswiezaniu albo ponownym ladowaniu pliku losuje zawsze "adres2".
Co zrobic, zeby poprawnie losowalo?(IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif) ? :?: :?: :?:
Go to the top of the page
+Quote Post
haiaw
post
Post #2





Grupa: Zarejestrowani
Postów: 50
Pomógł: 0
Dołączył: --
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


Cytat
Czemu to nie dziala?(IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif) (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif)
przy kazdym odswiezaniu albo ponownym ladowaniu pliku losuje zawsze "adres2".
Co zrobic, zeby poprawnie losowalo?(IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif) ? :?:  :?:  :?:


RTFM!!!!!

Cytat
void shuffle (array array)


This function shuffles (randomizes the order of the elements in) an array. You must use srand() to seed this function.  
Go to the top of the page
+Quote Post
Sir Blade
post
Post #3





Grupa: Zarejestrowani
Postów: 211
Pomógł: 0
Dołączył: 7.06.2002

Ostrzeżenie: (0%)
-----


haiaw !!!

troche cierpliwosci dla 'mlodych'.. (IMG:http://forum.php.pl/style_emoticons/default/laugh.gif)


a swoja droga to nalezy gdzies na glownej stronie walnac cos a'la 'dobre rady' i napisac zeby czytali manual ....
Go to the top of the page
+Quote Post
Sir Blade
post
Post #4





Grupa: Zarejestrowani
Postów: 211
Pomógł: 0
Dołączył: 7.06.2002

Ostrzeżenie: (0%)
-----


jakby mlody nie kumal z angielskiego :



Cytat
shuffle
(php 3>= 3.0.8, php 4 >= 4.0.0)

shuffle -- Przetasuj tablicę
Opis
void shuffle ( array tablica)


Ta funkcja tasuje tablicę (losuje kolejność elementów w niej). Musisz użyć srand() aby przygotować ziarno dla tej funkcji. Przykład 1. Przykład użycia shuffle()

$liczby = range (1,20);
srand ((float)microtime()*1000000);
shuffle ($liczby);
while (list (, $liczba) = each ($liczby)) {
   echo "$liczba ";
}
 
 
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 23.08.2025 - 05:29