1

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] => [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
    )

And here is my PHP code.

    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;
}

1 Answer 1

4

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

foreach($feed as &$f) {
  $f['user']=$f[0];
  unset($f[0]);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.