douchen1988 2016-10-04 06:17
浏览 151
已采纳

array_diff()函数没有显示正确的结果

array_diff() function not showing correct result:-

First Array:-

     Array(
    [designation_id] => 1
    [name] => Y
    [fathers_name] => Z
    [mothers_name] => F
    [spouse_name] => d
    [gender] => F
    [last_achieved_degree] => 2
    [date_of_birth] => 1960-10-17
    [date_of_joining] => 1987-02-04
)

Second array:-

 Array
    (
        [designation_id] => 9
        [name] => M
        [fathers_name] => N
        [mothers_name] => O
        [spouse_name] => 
        [gender] => M
        [last_achieved_degree] => 1
        [date_of_birth] => 1967-11-17
        [date_of_joining] => 2016-01-01
    )

Output:

    Array
(
    [name] => Y
    [fathers_name] => Z
    [mothers_name] => F
    [spouse_name] => d
    [gender] => F
    [last_achieved_degree] => 2
    [date_of_birth] => 1960-10-17
    [date_of_joining] => 1987-02-04
)

designation id column not showing in output result. if designation-id value is 1 then this index not showing in output otherwise it showing. is it bug or something else?

  • 写回答

2条回答 默认 最新

  • dqwh0109 2016-10-04 06:34
    关注

    Since your arrays are associative array, so you need to use array_diff_assoc:-

    <?php
    
     $a =   Array(
        'designation_id' =>1,
        'name' => 'Y',
        'fathers_name' => 'Z',
        'mothers_name' => 'F',
        'spouse_name' => 'd',
        'gender' => 'F',
        'last_achieved_degree' => 2,
        'date_of_birth' => '1960-10-17',
        'date_of_joining' => '1987-02-04'
    );
    
    $b =Array
    (
        'designation_id' => 9,
        'name' => 'M',
        'fathers_name' => 'N',
        'mothers_name' => 'O',
        'spouse_name' => '',
        'gender' => 'M',
        'last_achieved_degree' => 1,
        'date_of_birth' => '1967-11-17',
        'date_of_joining' => '2016-01-01',
    );
    
    echo "<pre/>";print_r(array_diff_assoc($a,$b));
    

    Output:-https://eval.in/654658

    to check more description and examples:- http://sg2.php.net/manual/en/function.array-diff-assoc.php

    Why array_diff() not worked:- https://stackoverflow.com/a/4742438/4248328

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

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧