私はおそらくこれを間違った方法で行っています。これが私がやろうとしていることです:
私は 2 つの配列を持っています。どちらも Jira バグ システムからのものです。1 つはコメント用で、もう 1 つは添付ファイル用です。API からプルするときはどちらも異なるオブジェクトですが、両方を組み合わせて表示し、結果を印刷して時系列で表示したいと考えています。注文。
たとえば、現在は次のとおりです。
comment 1 - 5th April
Comment 2 - 20th April
comment 3 - 9th June
attachment 1 - 5th April
attachment 2 - 20th April
I want to dislay that as:
comment 1 - 5th April
attachment 1 - 5th April
Comment 2 - 20th April
attachment 2 - 20th April
comment 3 - 9th June
わかりましたので、ここに私の添付ファイル配列があります:
$attachments = $issue_json->fields->attachment;
$result1 = array();
foreach ($attachments as $attachment)
{
$result1[] = array
(
'attachment_date' => convert_time($attachment->created),
'attachment_epoch' => convert_sql_time($attachment->created),
'attachment_displayName' => $attachment->author->displayName,
'attachment_filename' => $attachment->filename,
'attachment_file_type' => $attachment->mimeType,
'attachment_thumbnail' => $attachment->thumbnail,
'attachment_url_link' => $attachment->content,
);
}
これにより、次の結果が得られます。
Array
( [0] => Array(
[attachment_date] => 13th Apr 12 07:10
[attachment_epoch] => 1334301000
[attachment_displayName] => XXX
[attachment_filename] => 1.txt
[attachment_file_type] => text/plain
[attachment_thumbnail] =>
[attachment_url_link] => https://xxx.atlassian.net/secure/attachment/18605/1.txt
)
[1] => Array(
[attachment_date] => 13th Apr 12 07:10
[attachment_epoch] => 1334301000
[attachment_displayName] => xxx
[attachment_filename] => 2.txt
[attachment_file_type] => text/plain
[attachment_thumbnail] =>
[attachment_url_link] => https://xxx.atlassian.net/secure/attachment/18606/2.txt
)
今コメント:
$comments = $issue_json->fields->comment->comments;
$result = array();
foreach ($comments as $comment)
{
$result[] = array
(
'comments_date' => convert_time($comment->updated),
'comments_epoch' => convert_sql_time($comment->updated),
'comments_displayName' => $comment->author->displayName,
'comments_body' => $comment->body,
);
}
出力の例を次に示します。
Array ( [0] => Array(
[comments_date] => 11th Apr 12 20:52
[comments_epoch] => 1334177520
[comments_displayName] => xxx
[comments_body] => Cannot reproduce, but attempted a fix based on the log file.
)
[1] => Array(
[comments_date] => 13th Apr 12 07:09
[comments_epoch] => 1334300940
[comments_displayName] => xxx
[comments_body] => 1) tested on a bit older version it still happens with it
)
今、私が計画していたのは2つの配列をマージすることでしたが、一致する変数がないため、それが可能かどうかはわかりません。
それを1つの大きなものにマージして、それに一致させる必要があるものを組み合わせることはできますか?これは、それでソートしたいエポック日付であるため、次のようなものになるまでそれらをマージします:
$result1[] = array
(
'date' => convert_time($attachment->created),
'epoch' => convert_sql_time($attachment->created),
'displayName' => $attachment->author->displayName,
'attachment_filename' => $attachment->filename,
'attachment_file_type' => $attachment->mimeType,
'attachment_thumbnail' => $attachment->thumbnail,
'attachment_url_link' => $attachment->content,
'comments_date' => convert_time($comment->updated),
'comments_epoch' => convert_sql_time($comment->updated),
'comments_displayName' => $comment->author->displayName,
'comments_body' => $comment->body,
);
したがって、最初の 3 つは両方の配列にあるため一致し、他のすべての配列には添付ファイルまたはコメントのいずれかの値がありますが、両方ではないため、1 つの大きな配列を取得したら、エポックで並べ替え、結果を時系列でエコーアウトできます。
それは機能しますか?もしそうなら、phpのどのマージコマンドが最適ですか?array_mergeまたは再帰的なコマンドですか? 私はおそらくそれを複雑にしすぎています、私はphpに慣れていないので、これで行くのに最適な方向に少し行き詰まっています