dongpo0409 2012-03-27 07:39
浏览 181
已采纳

php array_diff_assoc()给出了错误的区别

i have two arrays, and i use array_diff_assoc() php function for get the difference, but it always returns the comm set as the difference, but it should be new q sets whats the wrong with this, please help

arrays--

Array ( [0] => Array ( [12] => new q sets ) [1] => Array ( [11] => common set ) ) 

Array ( [0] => Array ( [11] => common set ) ) 

after use array_diff_assoc() o p

Array ( [1] => Array ( [11] => common set ) ) 
  • 写回答

2条回答 默认 最新

  • du131642 2012-03-27 07:49
    关注

    Two values from key => value pairs are considered equal only if (string) $elem1 === (string) $elem2 . In other words a strict check takes place so the string representations must be the same.

    http://php.net/manual/en/function.array-diff-assoc.php

    The (string) value of any array is "Array". Thus, your call to array_diff_assoc is effectively comparing these two things:

    Array ( [0] => "Array" [1] => "Array" ) 
    Array ( [0] => "Array" ) 
    

    Since the thing that is different between those two is the [1] key/value pair from the first array, you get that back ([1] => Array( [11] => common set )).

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

报告相同问题?

悬赏问题

  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码