Machuss Posted May 3, 2006 Report Share Posted May 3, 2006 <?php $kartas_nummurs = rand(1, 3); $izvelne = rand(0, 2); $opt1 = array("viens", "divi", "trīs"); $opt2 = array("Es", "Vinjsh", "Vinja"); $opt3 = array("mazs", "normals", "liels"); echo "Izveilne :".$opt.$kartas_nummurs."[".$izvelne."]"; ?> Aptuveni šādi ir iespējams panākt lai skirpts darbotos un tiktu izveeleets viens konkrēts vārds? Zinu ka ar DB šādi ir vieglāk, bet kā man rīkoties, varbuut kaads var man paliidzeet? Link to comment Share on other sites More sharing options...
Delfins Posted May 3, 2006 Report Share Posted May 3, 2006 neko nesapratu.. Link to comment Share on other sites More sharing options...
Blitz Posted May 3, 2006 Report Share Posted May 3, 2006 <?php $kartas_nummurs = rand(1, 3); $izvelne = rand(0, 2); $opt1 = array("viens", "divi", "tris"); $opt2 = array("Es", "Vinjsh", "Vinja"); $opt3 = array("mazs", "normals", "liels"); $opt="opt".$kartas_nummurs; $opt=$$opt; echo "Izveilne :$opt[$izvelne]" ?> Link to comment Share on other sites More sharing options...
Machuss Posted May 4, 2006 Author Report Share Posted May 4, 2006 bet ja vajadzeetu panaakt lai vienlaiciigi rand() izveeleetos divus dazhaadus vaardus? Link to comment Share on other sites More sharing options...
Klez Posted May 4, 2006 Report Share Posted May 4, 2006 $a1 = rand(0,2); //shis pirmajam $a2 = rand(0,2); //shis otrajam Link to comment Share on other sites More sharing options...
Machuss Posted May 4, 2006 Author Report Share Posted May 4, 2006 (edited) $a1 = rand(0,2); //shis pirmajam$a2 = rand(0,2); //shis otrajam ideja man skaidra, bet neizdodas :) vajadziigs lai nebuutu iespeejamiiba ka $a1 un $a2 ir vienaadi meegjinaaju gan ar while gan if , bet nekas nesanaaca. Edited May 4, 2006 by Machuss Link to comment Share on other sites More sharing options...
Klez Posted May 4, 2006 Report Share Posted May 4, 2006 pieliec klaat: if ($a1 == $a2) $a2++; Link to comment Share on other sites More sharing options...
Grey_Wolf Posted May 4, 2006 Report Share Posted May 4, 2006 (edited) Machuss--> tieshaam slinkums apskatiities te ? tur ir gana labi piemeeri ... edit: katckad stipri sen panjemts no turienes function randomaizeris($min,$max,$num) { $ret = array(); if ($max<($num-1)) { return false; } while (count($ret) <$num) { do { $a = rand($min,$max); } while (in_array($a,$ret)); $ret[] = $a; } return($ret); } Klez --> taa nav paraak labi dariit liels % ka iziesi aarpus atljautajaam vertiibaam + ko dariit ja peksnji vajag 3 vai 30 dazaadas vertiibas? Edited May 4, 2006 by Grey_Wolf Link to comment Share on other sites More sharing options...
Machuss Posted May 4, 2006 Author Report Share Posted May 4, 2006 Laikam man buus jaaiet pie okulista :) nepamaniiju ka tur jau viss priekshaa Link to comment Share on other sites More sharing options...
Klez Posted May 4, 2006 Report Share Posted May 4, 2006 (edited) Grey_Wolf, Machuss rakstiija: "vajadziigs lai nebuutu iespeejamiiba ka $a1 un $a2 ir vienaadi" $max = 100; $min = 10; $a1 = rand($min,$max); $a2 = rand($min,$max); if ($a1 == $a2) if ($a2 >= $max) $a2--; else $a2++; Edited May 4, 2006 by Klez Link to comment Share on other sites More sharing options...
Grey_Wolf Posted May 4, 2006 Report Share Posted May 4, 2006 Klez--> tieshi taa :) manis iedotajaa f-ja izmanot konstrukciju DO WHILE :) izpeeti vinju ruupiigaak :) sakumaa uzgeneree randomu un tikai tad saliidzinam :) ja masiivaa Jau ir elements tad turpinam kameer nav :) un tikai tad pievienojam masiivam :) Link to comment Share on other sites More sharing options...
Klez Posted May 5, 2006 Report Share Posted May 5, 2006 varianti ir dazhaadi kaa to panaakt :) .. Link to comment Share on other sites More sharing options...
Recommended Posts