将多维数组与内部数组进行比较以获得下一个键

时间:2013-12-18 11:21:48

标签: php arrays function multidimensional-array compare

 Array
(
    [6000] => Array
        (
            [2225] => Array
                (
                    [0] => Array
                        (
                            [MarketCode] => SE
                            [Type] => Värmesystem
                            [Value] => AC/ACC
                        )

                    [1] => Array
                        (
                            [MarketCode] => SE
                            [Type] => Volym
                            [Value] => 0,5 Liter
                        )
                    [2] => Array
                        (
                            [MarketCode] => SE
                            [Type] => Fordontrustning
                            [Value] => Med Ac
                        )

                )

            [2224] => Array
                (
                    [0] => Array
                        (
                            [MarketCode] => SE
                            [Type] => Värmesystem
                            [Value] => AC/ACC
                        )

                    [1] => Array
                        (
                            [MarketCode] => SE
                            [Type] => Volym
                            [Value] => 0,5 Liter
                        )
                    [2] => Array
                        (
                            [MarketCode] => SE
                            [Type] => Fordontrustning
                            [Value] => Med Coll
                        )

                )

        )

    [18000] => Array
        (
            [2214] => Array
                (
                    [0] => Array
                        (
                            [MarketCode] => SE
                            [Type] => Värmesystem
                            [Value] => AC/ACC
                        )

                    [1] => Array
                        (
                            [MarketCode] => SE
                            [Type] => Volym
                            [Value] => 0,5 Liter
                        )
                     [2] => Array
                        (
                            [MarketCode] => SE
                            [Type] => Fordontrustning
                            [Value] => Med Ac
                        )

                )

            [2213] => Array
                (
                    [0] => Array
                        (
                            [MarketCode] => SE
                            [Type] => Värmesystem
                            [Value] => AC/ACC
                        )

                    [1] => Array
                        (
                            [MarketCode] => SE
                            [Type] => Volym
                            [Value] => 0,5 Liter
                        )
                     [2] => Array
                        (
                            [MarketCode] => SE
                            [Type] => Fordontrustning
                            [Value] => Med Coll
                        )

                )

        )

)

如何在给定数组中进行比较?

我的意思是如何比较键值6000的2225到2224的索引

我试图比较像多维数组,但它不起作用,

渴望输出

[2] => Array
                    (
                        [MarketCode] => SE
                        [Type] => Fordontrustning
                        [Value] => Med Ac
                    )
                    Because it is different from [2224] => Array of [2] => Array
                    (
                        [MarketCode] => SE
                        [Type] => Fordontrustning
                        [Value] => Med Coll
                    )

直到我试试这个

                           foreach($miles as $m => $k){
                               foreach($miles as $key => $val){
                                   if($key != $m){
                                    for($j=0;$j<=count($k);$j++){
                                        for($x=0;$x<=count($val);$x++){

                                            if($k[$j][0]!=$val[$x][0] && !empty($k[$j]) && !empty($val[$x])){
                                                echo "start";
                                                print_r($k[$j]);
                                            echo ".......<br>";
                                            print_r($val[$x]);    
                                            echo "end";
                                            }

                                        }
                                    }
                                   }
                               }
                           }
                        }

如果内置的php功能还有其他方法,请帮助我吗?

0 个答案:

没有答案