我有循環問題,我想表明重播隨意循環要顯示循環兩個隨機循環和交叉
代碼:
for ($i=0; $i <= 10; $i++) {
$result = $i;
echo "$result";
echo "<br>";
}
//----------------------------------------------
echo "<hr width='100%'>";
//----------------------------------------------
$s=$result;
$c=$result;
$test=array_fill($s, $c, 0);
$ts=microtime(true);
for ($i=0; $i <= 10; $i++) {
$selection1=mt_rand($s, $c);
$selection2=mt_rand($s, $c);
echo "$selection1 and $selection1";
echo "<br>";
}
我想要的結果: example result
隨機後我想交叉循環 Example result
#including completion of a genetic algorithm
歡迎來到Stack Overflow!請參閱[問]和[完美問題](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/)。 – Rizier123
因爲它已經在你的最後一個問題中提到過:http://stackoverflow.com/q/37220786/3933332 for循環運行後'$ result'將爲10。 (順便說一下,在for循環中你的變量的引號是不必要的)。所以之後你把10賦給'$ s'和'$ c'。 (與此同時,您將創建一個數組,從索引10開始,10個元素的值爲0)。在下一個for循環中,您可以創建10到10之間的隨機值,隨機值是隨機值。所以大多數你會得到10! – Rizier123
我仍然困惑,如果我想要結果如上,我應該做什麼,請包括編碼先生的例子? –