开发者

Add Array To Array

I have been able to add 2 arrays together in my script. The problem is, as seen below, the second item in the array is name [0] I need this to say [user].

    [0] => Array
    (
        [id] => 1
        [0] => Array
            (
                [id] => 1
                [first_name] => Cody
                [last_name] => Robertson
                [email] => codyrob@me.com
                [password] => 
                [age] => 16
                [city] => Commerce Township
                [country] => United States Of America
                [friends] => 
                [avatar] => http://blazebyte.org/community/index.php?action=dlattach;attach=4415;type=avatar
                [register_date] => 2011-09-03
                [laststatus_date] => 0000-00-00
            )

        [status] => This is my first status. Will be pulled from API. :D
        [date] => 2011-09-02 23:26:09
    )

And here is my PHP code.

    public function all_g开发者_如何转开发et()
{
    $feed = array();
    $data = array();

    $query = $this->db->query('SELECT * FROM `statuses`');

    if($query->num_rows() > 0)
    {
        $statuses = $query->result_array();

        foreach($statuses as $status)
        {
            $i = 0;

            $query = $this->db->query('SELECT * FROM `members` WHERE id='. $status['uid']);

            if($query->num_rows() > 0)
            {
                $user = $query->result_array();

                $first = array_slice($status, 0, 1, true);
                $secnd = array_slice($status, 2, null, true);

                foreach($user as $info => $value)
                {
                    $data[$info] = $value;
                }

                $feed[] = array_merge( (array) $first, (array) $data, (array) $secnd);
            }

        }   
    }

    return $feed;
}


Quick fix would be: (insert this just before return)

foreach($feed as &$f) {
  $f['user']=$f[0];
  unset($f[0]);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜