0

How to combine multiple arrays in to single array ?

Here's my code:

while($row = db_fetch_array($query)) {

        print_r($row);        

        //foreach($row as $value) {
        //   $to_gid = $value['to_gid'];
        //   //unset($value['to_gid']);
        //   $new_gid[$to_gid][] = $value;
        //}
}

EDITED:

print_r prints the below output:

    Array
(
    [to_gid] => 6012
)

Array
(
    [to_gid] => 8227
)

Array
(
    [to_gid] => 8227, 6012
)

But my expected o/p is :

Array
(
    [to_gid] => 8227, 6012
)

commented foreach is the thing what i have tried :-(

What should i need to do to achieve this?

thanks in advance...

2 Answers 2

0

to combine multiple arrays you have to have multiple arrays, not multiple objects.

$new_gid = array();
while($row = db_fetch_assoc($query)) { //I hope you have such a function
    $new_gid[$row['to_gid']][] = $row;
}
0

I think array_merge is what you are looking for.

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.