Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
amprog_05_ex1 [2016-10-17 10:49] Anders Mosshäll |
amprog_05_ex1 [2017-10-19 09:40] Anders Mosshäll |
||
---|---|---|---|
Line 14: | Line 14: | ||
$slump = mt_rand(1, | $slump = mt_rand(1, | ||
- | $slumpaom | + | $exist = false; |
| | ||
- | $x = 0; | + | $j = 0; |
- | while ($x < count($tal)){ // Finns talet reda i arrayen? | + | while ($j < count($tal)){ // Finns talet reda i arrayen? |
- | if ($tal[$x] == $slump){ | + | if ($tal[$j] == $slump){ |
- | $slumpaom | + | $exist = true; |
} | } | ||
- | $x++; | + | $j++; |
} | } | ||
| | ||
- | if ($slumpaom | + | if ($exist == false){ |
$tal[] = $slump; | $tal[] = $slump; | ||
+ | $slumpaom = false; | ||
} | } | ||
} | } | ||
Line 33: | Line 34: | ||
//Skriv ut arrayen. | //Skriv ut arrayen. | ||
- | $x = 0; | + | $i = 0; |
- | while ($x < count($tal)){ | + | while ($i < count($tal)){ |
- | echo $tal[$x].'< | + | echo $tal[$i].'< |
- | $x++; | + | $i++; |
} | } | ||