Help with Merging Arrays

ok I have 2 array values… That’s coming from 2 different methods in my class file.

This is coming from my Keyword Method

Array
(
    [4193] => Array
        (
            [Tagged] => Array
                (
                    [0] => Keratin Treatment
                    [1] => Couples Massage
                )

        )

    [3574] => Array
        (
            [Tagged] => Array
                (
                    [0] => Deep Massage
                )

        )

)

this is coming from another method

Array
(
    [4193] => Array
        (
            [salonID] => 4193
            [miles] => 0.283011807234213
            [featured] => 3
        )

    [3574] => Array
        (
            [salonID] => 3574
            [miles] => 0.718207507865745
            [featured] => 3
        )

)

I want to merge the two to look like this


Array
(
    [4193] => Array
        (
            [salonID] => 4193
            [miles] => 0.283011807234213
            [featured] => 3
            [Tagged] => Array
                (
                    [0] => Keratin Treatment
                    [1] => Couples Massage
                )

        )

    [3574] => Array
        (
            [salonID] => 3574
            [miles] => 0.718207507865745
            [featured] => 3
            [Tagged] => Array
                (
                    [0] => Deep Massage
                )

        )

)

I tried the following techniques

$Results = $arr_value_a+$arr_value_b it resets the keys…
and other array merging functions provided by php resets the keys or just ends up deleting half the arrays…

So i found a function on Stock OverFlow

which does this

Array
(
    [4193] => Array
        (
            [0] => Array
                (
                    [salonID] => 4193
                    [miles] => 0.283011807234213
                    [featured] => 3
                )

            [1] => Array
                (
                    [Tagged] => Array
                        (
                            [0] => Keratin Treatment
                            [1] => Couples Massage
                        )

                )

        )

    [3574] => Array
        (
            [0] => Array
                (
                    [salonID] => 3574
                    [miles] => 0.718207507865745
                    [featured] => 3
                )

            [1] => Array
                (
                    [Tagged] => Array
                        (
                            [0] => Deep Massage
                        )

                )

        )

)

Almost Perfect… but the problem is i don’t want the auto count inside my array.

This is what i’m using

function merge_common_keys(){
    $arr = func_get_args();
    $num = func_num_args();

    $keys = array();
	

    $i = 0;
    for($i=0;$i<$num;++$i){
        $keys = array_merge($keys, array_keys($arr[$i]));
    }
		
    $keys = array_unique($keys);
	
    $merged = array();

    foreach($keys as $key){
        $merged[$key] = array();
        for($i=0;$i<$num;++$i){
            $merged[$key][] = isset($arr[$i][$key])?$arr[$i][$key]:null;
        }
    }
    return $merged;
}

Can someone help me modify this so it doesn’t automatically auto count keys.

LMAO!! Nevermind i figured it out … i just needed to go for a walk. was coding for 12hours straight :\

Hi Shaydez,

Not sure if this is the same solution you arrived at in the end, but [fphp]array_replace_recursive[/fphp] will also get you the result you want.

array_intersect_key i used… worked like a charm .