douguai6716 2014-03-07 11:45
浏览 56

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

I have a array called $array which is multidimensional array. It consits of keys like brandname, productsubcategory (Keys are not static they can be anything and even number of keys are not fixed). I want all the common values from the array

Current array:

$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
                )

        )

);

Desired array :

$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条回答 默认 最新

  • dounai6613 2014-03-07 11:56
    关注

    Use array_intersect():

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

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了