0
我已創建5個的整數數組中,我希望循環這些通過一個多維陣列5個陣列內部(含各5點的整數)。如果有任何匹配的數字,我會在最後回覆這些數字。到目前爲止,該計劃運作良好。我的問題是:我要遍歷一個數組,但需要檢查2組不同的整數的一個陣列
1.how do I insure all integers in $drawnum are unique, I.E when I create the random number array no numbers will repeat.
在$ ticketnum前五個整數和$ drawnum是1之間 - 3.I 50 希望在$ ticketnum末尾添加2個整數和$ drawnum該範圍1之間 - 13
如何運行一個循環遍歷每個數組因此$ drawnum的前5個整數將檢查$ ticketnum第5點的整數。
如何通過每個陣列運行循環,使$ drawnum的最後2個整數將檢查$ ticketnum最後2個整數。
這裏是我到目前爲止的代碼:
<?php
$rand6 = rand(1, 10);
$rand7 = rand(1, 10);
$rand8 = rand(1, 10);
$rand9 = rand(1, 10);
$rand10 = rand(1, 10);
$randstar = rand (1, 13);
$randstar1 = rand (1, 13);
$compare = 0;
$one = 0;
$two = 0;
$three = 0;
$four = 0;
$five = 0;
//Begin loop
for ($i=0; $i<=5; $i++){
$x = 0;
$rand6 = rand(1, 50);
$rand7 = rand(1, 50);
$rand8 = rand(1, 50);
$rand9 = rand(1, 50);
$rand10 = rand(1, 50);
// I want to loop this random number array through the multidimensional array
$drawnum = array($rand6,$rand7,$rand8,$rand9,$rand10);
$ticketnum = array(
array(32,22,6,14,33),
array(1,14,16,48,8),
array(26,12,7,15,2),
array(21,18,25,44,50),
array(38,50,18,19,32),
);
//compare the 2 arrays to see if any numbers match.
$compare = array_intersect($drawnum, $ticketnum[$x]);
$ans = count($compare);
if ($ans == 1){
$one = $one + 1;
}
if ($ans == 2){
$two = $two + 1;
}
if ($ans == 3){
$three = $three + 1;
}
if ($ans == 4){
$four = $four + 1;
}
if ($ans == 5){
$five = $five + 1;
}
$x++;
}
echo "1 Number = " . $one . "</br>";
echo "2 Number = " . $two . "</br>";
echo "3 Number = " . $three . "</br>";
echo "4 Number = " . $four . "</br>";
echo "5 Number = " . $five . "</br>";
?>
我理解的foreach和in_array工作,但遇到的問題林是如何如何去通過循環編寫代碼迴路。 –