从php中的单个多维数组中获取公共值

时间:2014-03-07 11:45:14

标签: php arrays multidimensional-array

我有一个名为$ array的数组,它是多维数组。它包含了诸如brandname,productsubcategory之类的键(键不是静态的,它们可以是任何东西,甚至许多键也不固定)。我想要数组中的所有常用值

当前数组:

$array = array
(
    [brandname] => Array
        (
            [0] => Array
                (
                    [0] => sony_brandname
                    [1] => touch screen_type
                    [3] => 2.8_size
                    [4] => gsm + gsm_sim_support
                    [5] => 2_primary_camera
                    [6] => 64 mb_internal_memory
                    [7] => 32_expandable_memory
                    [8] => 1200_standard_battery_type
                    [9] => 3_size
                [10] => 1000_standard_battery_type
                [11] => touch and type_type         
                )

        )

    [productsubcategory] => Array
        (
            [1] => Array
                (
                    [0] => karbonn_brandname
                    [1] => touch and type_type
                    [2] => micromax_brandname
                    [3] => 2.8_size
                    [4] => gsm_sim_support
                    [5] => 3.15_primary_camera
                    [6] => 52 mb_internal_memory
                    [7] => 8_expandable_memory
                    [8] => 1000_standard_battery_type
                    [9] => nokia_brandname
                    [10] => symbian s40_os_clean
                    [11] => 5_primary_camera
                    [12] => 128 mb_ram
                    [13] => 256 mb_internal_memory
                    [14] => 32_expandable_memory
                    [15] => 1110_standard_battery_type
                    [16] => gsm + gsm_sim_support
                    [17] => 2_primary_camera
                    [18] => 32 mb_ram
                    [19] => 10 mb_internal_memory
                    [20] => no_expandable_memory
                    [21] => 1020_standard_battery_type
                    [22] => 680 mhz_processor
                    [23] => 64 mb_ram
                    [24] => 128 mb_internal_memory
                    [25] => 860_standard_battery_type
                    [26] => blackberry_brandname
                    [27] => 2.45_size
                    [28] => 1 ghz_processor
                )

        )

);

所需数组:

$array = array
(
    [0] => sony_brandname
    [1] => touch and type_type
    [2] => 2.8_size
    [8] => 1000_standard_battery_type
    [16] => gsm + gsm_sim_support
    [17] => 2_primary_camera
)

1 个答案:

答案 0 :(得分:1)

使用array_intersect()

$result = array_intersect($array["brandname"][0], $array["productsubcategory"][1]);
print_r($result);