0

i have a multi-dimentional array:

$array['hello'][0][0]='a';
$array['hello'][0][1]='b';
$array['hello'][0][2]='c';
$array['hello'][0][3]='d';
$array['hello'][1][0]='e';
$array['hello'][1][1]='f';
$array['hello'][1][2]='g';
 .... // and so on

i want to merge them all and want it as

$hello[1] = 'a';
$hello[2] = 'b';
$hello[3] = 'c';
$hello[4] = 'd';
$hello[5] = 'e';
$hello[6] = 'f';
$hello[7] = 'g';
 .... // and so on

now i have been using array_merge :

 $hello = array_merge($array['hello'][0],$array['hello'][1]);

But in this i have to be specific regarding the keys ie. 0,1 . what if keys are not known.

Is there any other way to do it ??

1 Answer 1

1

This should work without the keys:

$hello = array();
foreach ($array['hello'] as $key => $value) {
    foreach ($value as $k => $v) {
            $hello[$k] = $v;
        }    
}
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.