回答編集履歴
4
情報の追加。
answer
CHANGED
@@ -68,4 +68,27 @@
|
|
68
68
|
array_push($array, $tmp);
|
69
69
|
}
|
70
70
|
var_dump( $array );
|
71
|
+
```
|
72
|
+
|
73
|
+
|
74
|
+
---
|
75
|
+
|
76
|
+
**追記:**
|
77
|
+
|
78
|
+
```PHP
|
79
|
+
$array_base = [ 187, 284 ];
|
80
|
+
$array = [];
|
81
|
+
foreach ( $array_base as $id ) {
|
82
|
+
$ids = get_post_ancestors( $id );
|
83
|
+
if ( empty( $ids ) ) continue;
|
84
|
+
$scores = [];
|
85
|
+
foreach ( $ids as $i ) {
|
86
|
+
$scores[] = get_post_meta( $i, 'score', true );
|
87
|
+
}
|
88
|
+
$array[] = [
|
89
|
+
'ids' => $ids,
|
90
|
+
'scores' => $scores
|
91
|
+
];
|
92
|
+
}
|
93
|
+
var_dump( $array );
|
71
94
|
```
|
3
情報の追加。
answer
CHANGED
@@ -48,4 +48,24 @@
|
|
48
48
|
array_push($array, $tmp);
|
49
49
|
}
|
50
50
|
var_dump( $array );
|
51
|
+
```
|
52
|
+
|
53
|
+
---
|
54
|
+
|
55
|
+
**追記:**
|
56
|
+
|
57
|
+
```PHP
|
58
|
+
$array_base = array( 187, 284 );
|
59
|
+
$array = array();
|
60
|
+
foreach ( $array_base as $id ) {
|
61
|
+
$ids = get_post_ancestors( $id );
|
62
|
+
if ( empty( $ids ) ) continue;
|
63
|
+
$scores = get_post_meta( $ids[ count( $ids ) - 1 ], 'score', true );
|
64
|
+
$tmp = [
|
65
|
+
'ids' => $ids,
|
66
|
+
'scores' => $scores
|
67
|
+
];
|
68
|
+
array_push($array, $tmp);
|
69
|
+
}
|
70
|
+
var_dump( $array );
|
51
71
|
```
|
2
情報の追加。
answer
CHANGED
@@ -27,4 +27,25 @@
|
|
27
27
|
[http://php.net/manual/ja/function.array-pop.php](http://php.net/manual/ja/function.array-pop.php)
|
28
28
|
|
29
29
|
【PHP: array_shift - Manual】
|
30
|
-
[http://php.net/manual/ja/function.array-shift.php](http://php.net/manual/ja/function.array-shift.php)
|
30
|
+
[http://php.net/manual/ja/function.array-shift.php](http://php.net/manual/ja/function.array-shift.php)
|
31
|
+
|
32
|
+
---
|
33
|
+
|
34
|
+
**追記:**
|
35
|
+
|
36
|
+
そもそも質問文の変数がおかしかったので整理。
|
37
|
+
```PHP
|
38
|
+
$array_base = array( 187, 284 );
|
39
|
+
$array = array();
|
40
|
+
foreach ( $array_base as $id ) {
|
41
|
+
$ids = get_post_ancestors( $id );
|
42
|
+
if ( empty( $ids ) ) continue;
|
43
|
+
$scores = get_post_meta( array_pop( $ids ), 'score', true );
|
44
|
+
$tmp = [
|
45
|
+
'ids' => $id,
|
46
|
+
'scores' => $scores
|
47
|
+
];
|
48
|
+
array_push($array, $tmp);
|
49
|
+
}
|
50
|
+
var_dump( $array );
|
51
|
+
```
|
1
質問が書き換わったため追記
answer
CHANGED
@@ -6,7 +6,25 @@
|
|
6
6
|
> ```
|
7
7
|
> 画面では以下のように表示されます。
|
8
8
|
> ```
|
9
|
-
string(5) "abcde"
|
9
|
+
> string(5) "abcde"
|
10
|
+
> ```
|
11
|
+
>
|
12
|
+
> 「string」は変数が文字列であることを示し、( )内にはそのバイト数が表示されます。ここでは半角の英数字が5つ格納されているため「5」となります。
|
13
|
+
|
14
|
+
---
|
15
|
+
|
16
|
+
**追記:**
|
17
|
+
|
18
|
+
```PHP
|
19
|
+
$ids = get_post_ancestors( $id );
|
20
|
+
if ( empty( $ids ) ) continue;
|
21
|
+
$scores = get_post_meta( array_pop( $id ), 'score', true );
|
10
22
|
```
|
11
|
-
|
23
|
+
【get_post_ancestors – WordPress私的マニュアル】
|
24
|
+
[https://elearn.jp/wpman/function/get_post_ancestors.html](https://elearn.jp/wpman/function/get_post_ancestors.html)
|
25
|
+
|
26
|
+
【PHP: array_pop - Manual】
|
12
|
-
|
27
|
+
[http://php.net/manual/ja/function.array-pop.php](http://php.net/manual/ja/function.array-pop.php)
|
28
|
+
|
29
|
+
【PHP: array_shift - Manual】
|
30
|
+
[http://php.net/manual/ja/function.array-shift.php](http://php.net/manual/ja/function.array-shift.php)
|