回答編集履歴

1

方針転換

2020/07/22 08:58

投稿

katahiromz
katahiromz

スコア186

test CHANGED
@@ -1 +1,19 @@
1
+ ```php
2
+
3
+ $levels = [1, 2, 3, 4, 5, 101, 102, 103, 104, 105, ...];
4
+
5
+ $found = -1;
6
+
7
+ for ($i = 0; $i < count($levels); $i++)
8
+
1
- SQLの`BETWEEN`キーワードをお使い下さい。
9
+ if ($levels[$i] == $levelID) {
10
+
11
+ $found = $i; break;
12
+
13
+ }
14
+
15
+ $minLevel = $levels[$found>=2 ? $found-2 : 0];
16
+
17
+ $maxLevel = $levels[$found+2 >= count($levels) ? count($levels) : $found+2];
18
+
19
+ ```