dongma1666 2012-05-25 05:22
浏览 18
已采纳

这个简单的代码有什么问题?

I want to compare the 2 arrays below and find the differences. The values for keys "lead owner" and "company" are different, but when I compare these arrays, it says only "company" values are different. But when I create 2 new arrays with only one key/value pair for "lead owner" it works properly. Am I making some mistake?

<?php

$arr1 = Array
    (
        "leadid" => "418176000000069007",
        "smownerid" => "418176000000047003",
        "lead owner" => "Amit Patil",
        "company" => "SAM",
        "first name" => "Test",
        "last name" =>"Lead1",
        "designation" => "call",
        "email" => "",
        "phone" => "958",
        "fax" => "",
        "mobile" => "",
        "website" => "www.infosys.con",
        "lead source" => "Cold Call",
        "lead status" => "Contact in Future",
        "industry" => "None",
        "no of employees" => "45000",
        "annual revenue" => "0",
        "rating" => "Active",
        "smcreatorid" => "418176000000047003",
        "created by" => "Amit Patil",
        "modifiedby" => "418176000000047003",
        "modified by" => "Amit Patil",
        "created time" => "2012-04-05 19:58:00",
        "modified time" => "2012-05-02 08:51:08",
        "street" => "",
        "city" => "",
        "state" => "",
        "zip code" => "",
        "country" => "",
        "description" => "",
        "skype id" => "",
        "email opt out" => "false",
        "salutation" => "Mr.",
        "secondary email" => ""
        );

$arr2 = Array
    (
        "leadid" => "418176000000069007",
        "smownerid" => "418176000000047003",
        "lead owner" => "Amit aaa",
        "company" => "SAM A",
        "first name" => "Test",
        "last name" => "Lead1",
        "designation" => "call",
        "email" => "",
        "phone" => "958",
        "fax" => "",
        "mobile" => "",
        "website" => "www.infosys.con",
        "lead_source" => "Cold Call",
        "lead_status" => "Contact in Future",
        "industry" => "None",
        "no_of_employees" => "45000",
        "annual_revenue" => "0",
        "rating" => "Active",
        "smcreatorid" => "418176000000047003",
        "created_by" => "Amit Patil",
        "modifiedby" => "418176000000047003",
        "modified_by" => "Amit Patil",
        "created_time" => "2012-04-05 19:58:00",
        "modified_time" => "2012-05-02 08:51:08",
        "street" => "",
        "city" => "",
        "state" => "",
        "zip_code" => "0",
        "country" => "",
        "description" => "",
        "skype_id" => "",
        "email_opt_out" => "false",
        "salutation" => "Mr.",
        "secondary_email" => ""
        );

$arr3 = array("lead owner" => "Amit Patil");
$arr4 = array("lead owner" => "Amit aaa");

print_r(array_diff($arr1,$arr2));
echo "<br>";
print_r(array_diff($arr3,$arr4));
?>

Output is as below

Array ( [company] => SAM )
Array ( [lead owner] => Amit Patil ) 
  • 写回答

5条回答 默认 最新

  • dongxing2692 2012-05-25 05:31
    关注

    If you want to diff between associative arrays so that the key-value pairs matter, not just the values, use array_diff_assoc, not array_diff.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b