Robin Bronston Robin Bronston - 5 months ago 24
PHP Question

Merge array key values - PHP

Hi all i need to merge the same key to convert to single array from multiple array list please any one help me to the problem

for example here the array.

Array
(
[0] => Array
(
[0] => Mr.
[1] => Mrs.
)

[1] => Array
(
[0] => Rob
[1] => Tam
)

[2] => Array
(
[0] => kar
[1] => Man
)

[3] => Array
(
[0] => 55345345345
[1] => 44545345435
)

)


i need the output is

Array
(
[0] => Array
(
[0] => Mr.
[1] => Rob
[2] => kar
[3] => 55345345345
)

[1] => Array
(
[0] => Mrs.
[1] => Tam
[2] => Man
[3] => 44545345435
)

)


Please any one help

Thanks

Answer
$a = array(
    0 => array(
        0 => 'Mr.',
        1 => 'Mrs.'
    ),

    1 => array
    (
        0 => 'Rob',
        1 => 'Tam'
    ),

    2 => array
    (
        0 => 'kar',
        1 => 'Man'
    ),

    3 => array
    (
        0 => 55345345345,
        1 => 44545345435
    )
);

$arr1 = array();
foreach($a as $arr)
{
    foreach($arr as $key=>$value)
    {
        $arr1[$key][] = $value;
    }
}

echo '<pre>';
print_r($arr1);

Use this one. You can get output same as you want.

Comments