如何在这里分组阵列?

时间:2014-10-29 11:20:17

标签: php arrays

我有两个表格,如标签和内容。我已经为这两个表写了内部联接。

我有像这样的代码..

$menu_array=array();
foreach($this->getArticlesByLabels as $k){
  $menu_array[$k['label_name']][]=$k;
}

它正在展示

Array
(
   [DON'T MISS] => Array
   (
      [0] => Array
      (
         [ID] => 108347
         [Category_id] => 11204
         [title] => Ram Charan\'s GAV movie: Live updates from movie hall
         [text_data] => afadsfas           
      )

这里显示带有标签名称的数据。我的意思是它按标签名称分组,但我想动态显示数据如何使用循环显示数据..

2 个答案:

答案 0 :(得分:0)

试试这个:

foreach($this->getArticlesByLabels as $k){
  echo $k['ID'];
  echo $k['Category_id'];
  echo $k['title'];
  echo $k['text_data'];
}

答案 1 :(得分:0)

也许:

$menu_array=array();
foreach($this->getArticlesByLabels as $k){
  $menu_array['label_name']= $k['label_name'];
}

或:

foreach($this->getArticlesByLabels as $k){
  $menu_array=array($k);
}

或标签名称:

foreach($this->getArticlesByLabels as $k){
  $menu_array=array($k['label_name']);
}