回答編集履歴
3
修正
answer
CHANGED
@@ -6,9 +6,10 @@
|
|
6
6
|
$categories = [];
|
7
7
|
|
8
8
|
// 中略
|
9
|
-
$ancestor = get_ancestors($cat_id, 'category');
|
9
|
+
$ancestor = get_ancestors($cat_id, 'category');
|
10
|
-
$ancestor = array_pop($ancestor);
|
10
|
+
$ancestor = array_pop($ancestor);
|
11
11
|
$categories[] = $ancestor;
|
12
|
+
|
12
13
|
//ループ終了後に
|
13
14
|
return $categories;
|
14
15
|
|
2
修正
answer
CHANGED
@@ -2,8 +2,14 @@
|
|
2
2
|
|
3
3
|
### 変更
|
4
4
|
```php
|
5
|
+
//ループ外で
|
6
|
+
$categories = [];
|
7
|
+
|
8
|
+
// 中略
|
5
9
|
$ancestor = get_ancestors($cat_id, 'category');
|
10
|
+
$ancestor = array_pop($ancestor);
|
11
|
+
$categories[] = $ancestor;
|
6
12
|
//ループ終了後に
|
7
|
-
return $
|
13
|
+
return $categories;
|
8
14
|
|
9
15
|
```
|
1
修正
answer
CHANGED
@@ -1,14 +1,9 @@
|
|
1
1
|
配列を戻すようにすれば良いと思います。
|
2
2
|
|
3
|
+
### 変更
|
3
4
|
```php
|
4
|
-
|
5
|
-
$categories = [];
|
6
|
-
|
7
5
|
$ancestor = get_ancestors($cat_id, 'category');
|
8
|
-
$ancestor = array_pop($ancestor);
|
9
|
-
$categories[] = $ancestor;
|
10
|
-
|
11
6
|
//ループ終了後に
|
12
|
-
return $
|
7
|
+
return $ancestor;
|
13
8
|
|
14
9
|
```
|