在Array中拆分用户名而不是ID

时间:2013-05-01 12:03:59

标签: php codeigniter

我正在创建一个类似于facebook的评论后系统的系统。我首先使用codeigniter。

我需要使用3个表来获取所有数据。 (用户的用户名,帖子发布,评论评论)

$data = $this->post_model->getPosts();

        foreach ($data as $data) {
            $user = $this->members_model->memberData($data['uye']);
            $comments = $this->post_model->getComments($data['id']);
            $new_data[] = array('nick' => $user['nick'], 'post' => $data['post'], 'comments'=>$comments);
        }

输出

Array (
     [0] => Array (
              [nick] => yusufalibozkir 
              [post] => try.
              [comments] => Array (
                             [0] => Array (
                                    [id] => 1 
                                    [user] => 1 
                                    [comment] => comment try 
                                    [post] => 1
                                   )
                             )
             )
      )

我想将用户的参数分割为1作为id为1的用户名。您的建议是什么?

1 个答案:

答案 0 :(得分:0)

这个问题非常不清楚,但你的意思是这样吗?

$alldata = $this->post_model->getPosts();

    foreach ($alldata as $data) {
        $user = $this->members_model->memberData($data['uye']);
        $comments = $this->post_model->getComments($data['id']);
        $comments['id'] = $user['nick'];
        $new_data[] = array('nick' => $user['nick'], 'post' => $data['post'], 'comments'=>$comments);
    }