Home >Backend Development >PHP Tutorial > 数组操作,小弟我会的函数没几个,翻手册也没找到,所以想找高手哪位高手帮改下

数组操作,小弟我会的函数没几个,翻手册也没找到,所以想找高手哪位高手帮改下

WBOY
WBOYOriginal
2016-06-13 13:52:561009browse

数组操作,我会的函数没几个,翻手册也没找到,所以想找高手谁帮改下。
$a=array('111','222','333','444','555','666','777'); //不变的
$a1=array('aa','bb','cc','dd','ee','ff','gg'); //初始数组



$a2=array('a1a','bb','cc','d2d','e3e','ff','gg'); //对a1进行新比较的数组
$a3=array_intersect_assoc($a1,$a2); //2个数组比较,留下相同的; Array ( [1] => bb [2] => cc [5] => ff [6] => gg )
$a4=array('1'=>'bbc','2'=>'cc','5'=>'ff','6'=>'gg2');//对a2进行新比较的数组
$a5=array_intersect_assoc($a3,$a4); //结果为 Array ( [2] => cc [5] => ff ) //最终相同的数组

//////////想用a1-a5 留下不同的?不知道有没函数可以这样?


//想留下相对于a1 值不同的值(a1a,d2d,e3e,bbc,gg2),同时保留a1不同值的键值对应的 $a - $1 的值组成一个二唯数组...
//下面想要的为最终需求 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
$gg=array('1'=>array('111','aa','a1a'),'2'=>array('222','bb','bbc'),'3'=>array('333','dd','d2d'),'4'=>array('555','ee','e3e'),'5'=>array('777','gg','gg2'));




?>



------解决方案--------------------
array_diff()

Statement:
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