找到两个数组中都存在的元素

时间:2015-05-06 03:05:20

标签: php

我有两个如下的数组:

数组1

Array ( [price] => 117.00 [recurring_profile] => [use_config_gift_message_available] => 1 [stock_data] => Array ( [use_config_manage_stock] => 1 [original_inventory_qty] => 100 [qty] => 100 [use_config_min_qty] => 1 [use_config_min_sale_qty] => 1 [use_config_max_sale_qty] => 1 [is_qty_decimal] => 0 [is_decimal_divided] => 0 [use_config_backorders] => 1 [use_config_notify_stock_qty] => 1 [use_config_enable_qty_increments] => 1 [use_config_qty_increments] => 1 [is_in_stock] => 1 ) [website_ids] => Array ( [0] => 1 ) [can_save_configurable_attributes] => [can_save_custom_options] => [can_save_bundle_selections] => [type_has_options] => [type_has_required_options] => ) 

ARRAY2

Array ( [price] => 118.0000 ) 

我用

$newarr =array_intersect_assoc($oldValues, $newValues);

但是$newarr会是空白的,有什么想法吗?

我的预期结果:

$newArray1 = Array ( [price] => 117.00 );

2 个答案:

答案 0 :(得分:0)

这是空白的,因为价格有不同的值117.00和118.0000

您可以尝试使用array_intersect_key

答案 1 :(得分:0)

array_intersect_assoc()只会返回键和值匹配的项目。