2011-09-03 92 views
1

我已经能够在我的脚本中一起添加2个数组。问题是,如下面看到的那样,在阵列中的第二项是名称[0]我需要这样说[用户]将数组添加到数组

[0] => Array 
    (
     [id] => 1 
     [0] => Array 
      (
       [id] => 1 
       [first_name] => Cody 
       [last_name] => Robertson 
       [email] => [email protected] 
       [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 
    ) 

这里是我的PHP代码。

public function all_get() 
{ 
    $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; 
} 

回答

4

快速修复将是:(只返回前插入此)

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