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 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!