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
我有一个名为$ array的数组,它是多维数组。它包含了诸如brandname,productsubcategory之类的键(键不是静态的,它们可以是任何东西,甚至许多键也不固定)。我想要数组中的所有常用值
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 个解决方案
#1
1
Use array_intersect():
使用array_intersect():
$result = array_intersect($array["brandname"][0], $array["productsubcategory"][1]);
print_r($result);
#1
1
Use array_intersect():
使用array_intersect():
$result = array_intersect($array["brandname"][0], $array["productsubcategory"][1]);
print_r($result);