当我从 mysql 数据库中检索文章信息时,我得到了一个这样的数组:
Array
(
[0] => Array
(
[CategoryID] => 3
[CategoryName] => Test Category
[Parent] => 0
[Thumb] => 0
[sort] => 8
[ArticleID] => 2
[ArticleCatgories] => 9,4,3
[ArticleTitle] => vxcvxcvx
[ArticleBody] => xcvxcvxcvxcv
[InGroup] => 0
[GroupID] => 0
[Published] => 1
[PublishTime] =>
[TermID] => 11
[TermSlug] => xcvxcvxcv
[RelatedID] => 2
[TermType] => article
)
[1] => Array
(
[CategoryID] => 4
[CategoryName] => Test Image
[Parent] => 0
[Thumb] => 0
[sort] => 4
[ArticleID] => 2
[ArticleCatgories] => 9,4,3
[ArticleTitle] => vxcvxcvx
[ArticleBody] => xcvxcvxcvxcv
[InGroup] => 0
[GroupID] => 0
[Published] => 1
[PublishTime] =>
[TermID] => 11
[TermSlug] => xcvxcvxcv
[RelatedID] => 2
[TermType] => article
)
[2] => Array
(
[CategoryID] => 9
[CategoryName] => Test Images
[Parent] => 0
[Thumb] => 7
[sort] => 2
[ArticleID] => 2
[ArticleCatgories] => 9,4,3
[ArticleTitle] => vxcvxcvx
[ArticleBody] => xcvxcvxcvxcv
[InGroup] => 0
[GroupID] => 0
[Published] => 1
[PublishTime] =>
[TermID] => 11
[TermSlug] => xcvxcvxcv
[RelatedID] => 2
[TermType] => article
)
}
并且由于文章属于多个类别,因此它会多次检索文章信息。如果它们具有相同的 ArticleID,我需要做的是将类别名称组合到一个子数组中,这样结果就变成了:
Array
(
[0] => Array
(
[CategoryName] => array('Test Category','Test Image','Test Images');
[Parent] => 0
[Thumb] => 0
[sort] => 8
[ArticleID] => 2
[ArticleCatgories] => 9,4,3
[ArticleTitle] => vxcvxcvx
[ArticleBody] => xcvxcvxcvxcv
[InGroup] => 0
[GroupID] => 0
[Published] => 1
[PublishTime] =>
[TermID] => 11
[TermSlug] => xcvxcvxcv
[RelatedID] => 2
[TermType] => article
)
}