Home > Backend Development > PHP Tutorial > PHP数组 有关问题

PHP数组 有关问题

WBOY
Release: 2016-06-13 10:44:45
Original
958 people have browsed it

PHP数组 问题
2个一维 数组 部分值相同 

array('0'=>'1','1'=>'2')

array('0'=>'1','1'=>'2','2'=>'3','3'=>'4')

去掉相同的部分

得出的结果

array('2'=>'3','3'=>'4')


------解决方案--------------------
$a=array('0'=>'1','1'=>'2');

$b=array('0'=>'1','1'=>'2','2'=>'3','3'=>'4');
print_r(array_diff($b,$a));
------解决方案--------------------
array_diff_assoc($a1, $a2);
需要注意的是 返回的差集是基于$a1,因此$a1应该是单元数最多的那个
$a1 = array('0'=>'1','1'=>'2','2'=>'3','3'=>'4');
$a2 = array('0'=>'1','1'=>'2');
------解决方案--------------------
array_diff() array_diff_assoc()

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template