我认为这就是你要找的。我把它$i--;
拿出break;
来是因为我看不到它们的目的,除非这是在一个更大的循环中,但我仍然不明白它们的目的。无论如何。
$i=$rows;
if ($rows>50){
$i = $i - 50;
if ($i != 0 && $i%3 == 0){
echo "<p>This ride is free</p>";
} else if ($i%3 == 2){
echo "<p>Next ride is free</p>";
}
} else if ($rows<=50){
if ($i != 0 && $i%5 == 0){
echo "<p>This ride is free</p>";
} else if ($i%5 == 4){
echo "<p>Next ride is free</p>";
}
}
在http://sandbox.onlinephpfunctions.com/上测试
for($rows=0;$rows<75;$rows++){
$i=$rows;
echo $rows;
if ($rows>50){
$i = $i - 50;
if ($i != 0 && $i%3 == 0){
echo ": This ride is free";
} else if ($i%3 == 2){
echo ": Next ride is free";
}
} else if ($rows<=50){
if ($i != 0 && $i%5 == 0){
echo ": This ride is free";
} else if ($i%5 == 4){
echo ": Next ride is free";
}
}
echo "\n";
结果:
0
1
2
3
4: Next ride is free
5: This ride is free
6
7
8
9: Next ride is free
10: This ride is free
11
12
13
14: Next ride is free
15: This ride is free
16
17
18
19: Next ride is free
20: This ride is free
21
22
23
24: Next ride is free
25: This ride is free
26
27
28
29: Next ride is free
30: This ride is free
31
32
33
34: Next ride is free
35: This ride is free
36
37
38
39: Next ride is free
40: This ride is free
41
42
43
44: Next ride is free
45: This ride is free
46
47
48
49: Next ride is free
50: This ride is free
51
52: Next ride is free
53: This ride is free
54
55: Next ride is free
56: This ride is free
57
58: Next ride is free
59: This ride is free
60
61: Next ride is free
62: This ride is free
63
64: Next ride is free
65: This ride is free
66
67: Next ride is free
68: This ride is free
69
70: Next ride is free
71: This ride is free
72
73: Next ride is free
74: This ride is free