array_diff() 函数未显示正确结果
array_diff() function not showing correct result
array_diff()
函数未显示正确结果:-
第一个数组:-
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
)
第二个数组:-
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
)
输出:
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
)
指定 ID 列未显示在输出结果中。
如果 designation-id 值为 1,则该索引不显示在输出中,否则显示。是错误还是其他原因?
array_diff
计算差异而不比较键。在第二个数组中,您有 [last_achieved_degree] => 1
删除 [designation_id] => 1
.
试试 array_diff_assoc
.
由于你的数组是关联数组,所以你需要使用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));
查看更多描述和示例:- http://sg2.php.net/manual/en/function.array-diff-assoc.php
为什么 array_diff()
不起作用:-
array_diff()
函数未显示正确结果:-
第一个数组:-
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
)
第二个数组:-
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
)
输出:
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
)
指定 ID 列未显示在输出结果中。 如果 designation-id 值为 1,则该索引不显示在输出中,否则显示。是错误还是其他原因?
array_diff
计算差异而不比较键。在第二个数组中,您有 [last_achieved_degree] => 1
删除 [designation_id] => 1
.
试试 array_diff_assoc
.
由于你的数组是关联数组,所以你需要使用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));
查看更多描述和示例:- http://sg2.php.net/manual/en/function.array-diff-assoc.php
为什么 array_diff()
不起作用:-