0

I have the following two arrays...

1) how could i get only the different key->value one? 2) how can i insert to mysql the second array?

// first array
$aa =  Array
            (
                [t_a] => Array
                    (
                        [0] => Array
                            (
                                [f_c] => LAL
                                [p_r] => RN
                                [id] => 
                                [gender] => m
                            )
                    )

                [t_b] => Array
                    (
                    )

                [t_l] => Array
                    (
                        [0] => Array
                            (
                                [p_lev] => 2
                                [p_date] => 
                                [p_r] => 
                            )
                    )

                [t_r] => Array
                    (
                        [0] => Array
                            (
                                [I_r] => 19
                            )

                    )

// second array

 $bb = Array
                (
                    [t_a] => Array
                        (
                            [0] => Array
                                (
                                    [f_c] => NAN
                                    [p_r] => RN
                                    [id] => 1214125
                                    [gender] => m
                                )
                        )

                    [t_b] => Array
                        (
                        )

                    [t_l] => Array
                        (
                            [0] => Array
                                (
                                    [p_lev] => 2
                                    [p_date] => 21
                                    [p_r] => 25
                                )
                        )

                    [t_r] => Array
                        (
                            [0] => Array
                                (
                                    [I_r] => 19
                                )

                        )

I have used the array_diff function but i get NULL.

please some one help?

4

2 回答 2

1
$aa=(array)$aa;
$bb=(array)$bb;
$result=array_diff($aa,$bb);
于 2013-08-09T12:52:34.750 回答
1

不清楚你想要什么。请举一个例子或你想要的输出。这是一种可能性:

$ser_aa = array_map(function($e){return serialize($e);}, $aa);
$ser_bb = array_map(function($e){return serialize($e);}, $bb);
$diff = array_diff($ser_aa, $ser_bb);
$out = array_map(function($e){return unserialize($e);}, $diff);
print_r($out);

输出:

Array
(
    [t_a] => Array
        (
            [0] => Array
                (
                    [f_c] => LAL
                    [p_r] => RN
                    [id] => 
                    [gender] => m
                )

        )

    [t_l] => Array
        (
            [0] => Array
                (
                    [p_lev] => 2
                    [p_date] => 
                    [p_r] => 
                )

        )

)
于 2013-08-09T15:37:53.803 回答