0

可能重复:
递归array_diff()?

数组 1 =>

    pr($plan_data);
    Array
    (
        [0] => Array
            (
                [AveragePrice] => 9.631161
                [EFLUrl] => http://www.championenergyservices.com/register/EFL_API.asp?rateid=161456
                [EarlyTerminationFee] => 150
                [HurricaneRecovery] => 0.132
                [MeterSurcharge] => 3.05
                [OffCycle] => 5
                [PUCAssessment] => 0.00167
                [PlanDescription] => Savings Champ-6
                [PlanId] => 57
                [PlanIssueDate] => 12/10/2012
                [PlanMonthlyFee] => 0
                [PlanName] => PN1058
                [PlanRate] => 9.3
                [PlanRenewablePercent] => 7.2
                [PlanTerm] => 6
                [PriorityMoveIn] => 36
                [ProviderDisplayName] => CenterPoint Energy
                [ProviderId] => 21
                [ProviderInternalName] => CNP_COAST
                [RateId] => 161456
                [RegularMoveIn] => 16
                [TDSPPassThrough] => 0.03791
                [TOCUrl] => http://www.championenergyservices.com/register/termsandconditions.asp?rateid=161456
                [YRACUrl] => http://www.championenergyservices.com/register/\affiliatefiles\YRAC.PDF
                [provider] => ces
                [ProductType] => Fixed
                [Rep] => Champion Energy Services
                [Zone] => 77479
            )

        [1] => Array
            (
                [AveragePrice] => 10.1311693
                [EFLUrl] => http://www.championenergyservices.com/register/EFL_API.asp?rateid=161458
                [EarlyTerminationFee] => 150
                [HurricaneRecovery] => 0.132
                [MeterSurcharge] => 3.05
                [OffCycle] => 5
                [PUCAssessment] => 0.00167
                [PlanDescription] => Savings Champ-12
                [PlanId] => 59
                [PlanIssueDate] => 12/10/2012
                [PlanMonthlyFee] => 0
                [PlanName] => PN1060
                [PlanRate] => 9.8
                [PlanRenewablePercent] => 7.2
                [PlanTerm] => 12
                [PriorityMoveIn] => 36
                [ProviderDisplayName] => CenterPoint Energy
                [ProviderId] => 21
                [ProviderInternalName] => CNP_COAST
                [RateId] => 161458
                [RegularMoveIn] => 16
                [TDSPPassThrough] => 0.03791
                [TOCUrl] => http://www.championenergyservices.com/register/termsandconditions.asp?rateid=161458
                [YRACUrl] => http://www.championenergyservices.com/register/\affiliatefiles\YRAC.PDF
                [provider] => ces
                [ProductType] => Fixed
                [Rep] => Champion Energy Services
                [Zone] => 77479
            )

        [2] => Array
            (
                [AveragePrice] => 10.4311743
                [EFLUrl] => http://www.championenergyservices.com/register/EFL_API.asp?rateid=161459
                [EarlyTerminationFee] => 150
                [HurricaneRecovery] => 0.132
                [MeterSurcharge] => 3.05
                [OffCycle] => 5
                [PUCAssessment] => 0.00167
                [PlanDescription] => Green Power-12
                [PlanId] => 60
                [PlanIssueDate] => 12/10/2012
                [PlanMonthlyFee] => 0
                [PlanName] => PN1061
                [PlanRate] => 10.1
                [PlanRenewablePercent] => 100
                [PlanTerm] => 12
                [PriorityMoveIn] => 36
                [ProviderDisplayName] => CenterPoint Energy
                [ProviderId] => 21
                [ProviderInternalName] => CNP_COAST
                [RateId] => 161459
                [RegularMoveIn] => 16
                [TDSPPassThrough] => 0.03791
                [TOCUrl] => http://www.championenergyservices.com/register/termsandconditions.asp?rateid=161459
                [YRACUrl] => http://www.championenergyservices.com/register/\affiliatefiles\YRAC.PDF
                [provider] => ces
                [ProductType] => Fixed
                [Rep] => Champion Energy Services
                [Zone] => 77479
            )
)

数组 2 =>

pr($temp_val);
Array
(
    [0] => Array
        (
            [id] => 6
            [PlanId] => 60
            [PlanName] => Bounce 12 + A/C Protection
            [PlanDescription] => Bounce 12 + A/C Protection - CNP
            [PlanTerm] => 12
            [PlanRate] => 
            [RateId] => 
            [PlanIssueDate] => 
            [PlanMonthlyFee] => 
            [EarlyTerminationFee] => 200.00000
            [AveragePrice] => 12.00000
            [HurricaneRecovery] => 
            [PlanRenewablePercent] => 
            [ProviderDisplayName] => 
            [ProviderId] => 1
            [provider] => bounce
            [ProductZoneId] => 353
            [Zone] => 77479
            [ProviderInternalName] => 
            [RegularMoveIn] => 
            [PriorityMoveIn] => 
            [OffCycle] => 
            [TDSPPassThrough] => 
            [PUCAssessment] => 
            [EFLUrl] => 
            [EFLLinkUrl] => http://www.bounceenergy.com/efls/bounce12.pdf
            [TOCUrl] => 
            [TOCLUrl] => http://www.bounceenergy.com/terms-of-service-fixed.pdf
            [YRACUrl] => 
            [YRACLUrl] => http://www.bounceenergy.com/yraac.pdf
            [REP_Name] => 
            [REP_PUCT] => 
            [customer_service_email] => 
            [toll_free_number] => 
            [status] => active
            [created] => 2012-12-14 12:40:05
            [modified] => 2012-12-14
        )

    [1] => Array
        (
            [id] => 18
            [PlanId] => 17
            [PlanName] => Online Only - 12
            [PlanDescription] => Online Only - 12
            [PlanTerm] => 12
            [PlanRate] => 
            [RateId] => 386
            [PlanIssueDate] => 
            [PlanMonthlyFee] => 100.00000
            [EarlyTerminationFee] => 175.00000
            [AveragePrice] => 10.00000
            [HurricaneRecovery] => 
            [PlanRenewablePercent] => 
            [ProviderDisplayName] => 
            [ProviderId] => 2
            [provider] => fulcrum
            [ProductZoneId] => 
            [Zone] => 77479
            [ProviderInternalName] => 
            [RegularMoveIn] => 
            [PriorityMoveIn] => 
            [OffCycle] => 
            [TDSPPassThrough] => 
            [PUCAssessment] => 
            [EFLUrl] => 
            [EFLLinkUrl] => 
            [TOCUrl] => 
            [TOCLUrl] => 
            [YRACUrl] => 
            [YRACLUrl] => 
            [REP_Name] => 
            [REP_PUCT] => 
            [customer_service_email] => 
            [toll_free_number] => 
            [status] => active
            [created] => 2012-12-14 12:40:15
            [modified] => 2012-12-14
        )
)

我想比较这两个数组,如果任何键值不同,我想把它换成不同的数组。

$result_val= array_diff_assoc($plan_data, $temp_val);

请帮帮我!

4

1 回答 1

1

尝试这样的事情:

function array_diff_assoc($a, $b) {
    $result = array();
    foreach ($a as $k => $v) {
        if ($b[$k] != $v) {
            $result[$k] = [$v, $b[$k]];
        }
    }
    return $result;
}
于 2012-12-14T11:09:41.033 回答