Cibiņš Posted June 4, 2010 Report Share Posted June 4, 2010 (edited) $vards1 = "Jaanka"; $vards2 = "Kazha"; $vards3 = "Pacans"; $vards4 = "Vladjiks"; Kaa iisti lai randomaa paraada vaardus (tikai vienu vardu piem Janka, refreshojot lapu paraada Vladjiks, atkal refreshojot - Kazha utt..nu ceru domu saprataat..), gribas panaakt kaukaa vienkaarshaaku variantu.. Itkaa shitas skripts ir bet man vinjsh neder..jo liek kkaadaa rakaa <br /> tagu, ja novaac to \n ta vispar nekas nestrada, gribas jau lai lapaa ir defineejumi nevis velk no teksta faila. <?php $filename = "vardi.txt"; $file = file($filename); srand((double)microtime()*1000000); while ($RandomRotator == "") { $RandomRotator = ereg_replace("\n","",$file[rand(0,count($file))]); } echo "$RandomRotator"; ?> un fails vardi.txt kur ir tie vaardi iekshaa Janka Kazha Pacans Vladjiks Edited June 4, 2010 by Cibiņš Quote Link to comment Share on other sites More sharing options...
briedis Posted June 4, 2010 Report Share Posted June 4, 2010 (edited) $names = array("loļiks", "petķa", "fedja", "lunis"); echo $names[rand(0,count($names)]; vai ja no faila: $names = file('fails.txt'); echo trim($names[rand(0,count($names))]); Edited June 4, 2010 by briedis Quote Link to comment Share on other sites More sharing options...
Cibiņš Posted June 4, 2010 Author Report Share Posted June 4, 2010 (edited) $names = array("loļiks", "petķa", "fedja", "lunis"); echo $names[rand(0,count($names)]; Paldies par paliidziibu bet raada Internal Server Error konkreeti uz sho failu taatad kkas nau te pareizi :p Reku ir tas ko vajadzeeja :p $input = array("Pacans", "Vladjiks", "Urla", "Dumaj", "Vii"); $rand_keys = array_rand($input, 2); echo $input[$rand_keys[0]]; Edited June 4, 2010 by Cibiņš Quote Link to comment Share on other sites More sharing options...
briedis Posted June 4, 2010 Report Share Posted June 4, 2010 (edited) Te bija pazudusi aizverošā iekava: $names = array("loļiks", "petķa", "fedja", "lunis"); echo $names[rand(0,count($names))]; Kas tev liekas efektīvāk - samaisīt visus masīva elementus (tas nozīmē cikls, vai pat vairāki), vai paņemt vienu elementu pēc random indeksa (atliek izdomāt vienu ciparu uz dullu, ņemot vērā kopējo elemetu skaitu)? Nevermind, palasīju manuāli... Edited June 4, 2010 by briedis Quote Link to comment Share on other sites More sharing options...
bubu Posted June 4, 2010 Report Share Posted June 4, 2010 Cibiņš: kādā jēgā vajag izvelēties divas masīva atslēgas, bet jāizmanto tikai viena? $input = array("Pacans", "Vladjiks", "Urla", "Dumaj", "Vii"); echo $input[array_rand($input)]; Quote Link to comment Share on other sites More sharing options...
Cibiņš Posted June 5, 2010 Author Report Share Posted June 5, 2010 Cibiņš: kādā jēgā vajag izvelēties divas masīva atslēgas, bet jāizmanto tikai viena? $input = array("Pacans", "Vladjiks", "Urla", "Dumaj", "Vii"); echo $input[array_rand($input)]; LIELS paldies bubu :):):) Nu jaa uz Localhosta mans variants gaaja bet uz servera nee..bet Tavs variants straadaa perfekti :)) Lidz ar to problema atrisinaata :) Quote Link to comment Share on other sites More sharing options...
Kemito Posted June 6, 2010 Report Share Posted June 6, 2010 Ak dievs :D Mazliet nesaprotu kapeč tu sākumā, ķipa savu kodu, katru vārdu speid iekš mainīgo? O_O SICK! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.