±¾ÎÄʵÀýÖÎoÁËPHP¶þάÊý×eÈ¥ÖصĽ¨¡£ÖÏi¸ø´o¼Ò¹(C)´o¼Ò²Î¿¼£¬¾ßÌaÈçÏ£º
¶¼ÖªµÀһάÊý×eÈ¥ÖØÓÃϵͳº¯Êý array_unique($arr)
È»ºo½ñÌiÎÒÓõ½¶þάÊý×eÁË£¬Ò²ÏeÈ¥ÖØ£¬°Ù¶ÈÒ»´o¶Ñ£¬¶¼Êǽ«¶þάתһά È»ºoʹÓÃarray_unique($arr)
¿´µÃÎÒºÜÄÕ»ð£¬ËuÒÔ¾o¶¨×Ô¼ºÐ´Ò»¸o¡£±ÈËuµÄ¼oµ¥ºÃ¶®£¬¼Ç¼ÏÂÀ´£¬ÒÔ±¸ºoÓÃ
header('content-type:text/html;charset=utf8');
$arr = array(
array('id'=>1,'psid'=>'P101','fullname'=>'¿Î³Ì¼Æ»®È«³Æ 101','userid'=>4),
array('id'=>1,'psid'=>'P101','fullname'=>'¿Î³Ì¼Æ»®È«³Æ 101','userid'=>3),
array('id'=>1,'psid'=>'P101','fullname'=>'¿Î³Ì¼Æ»®È«³Æ 101','userid'=>3),
array('id'=>1,'psid'=>'P101','fullname'=>'¿Î³Ì¼Æ»®È«³Æ 101','userid'=>2),
array('id'=>2,'psid'=>'P102','fullname'=>'пγ̼ƻ®','userid'=>4),
array('id'=>2,'psid'=>'P102','fullname'=>'пγ̼ƻ®','userid'=>3),
array('id'=>2,'psid'=>'P102','fullname'=>'пγ̼ƻ®','userid'=>3),
array('id'=>2,'psid'=>'P102','fullname'=>'пγ̼ƻ®','userid'=>2)
);
$arr = er_array_unique($arr);
foreach($arr as $v){
echo 'id: '.$v['id'].'psid: '.$v['psid'].' fullname: '.$v['fullname'].' userid: '.$v['userid'].'<br/>';
}
//¶þάÊý×e¼oµ¥È¥ÖØ
function er_array_unique($arr){
$newarr = array();
if(is_array($arr)){
foreach($arr as $v){
if(!in_array($v,$newarr,true)){
$newarr[] = $v;
}
}
}else{
return false;
}
return $newarr;
}
´oÓ¡½a¹u£º
id: 1psid: P101 fullname: ¿Î³Ì¼Æ»®È«³Æ 101 userid: 4
id: 1psid: P101 fullname: ¿Î³Ì¼Æ»®È«³Æ 101 userid: 3
id: 1psid: P101 fullname: ¿Î³Ì¼Æ»®È«³Æ 101 userid: 2
id: 2psid: P102 fullname: пγ̼ƻ® userid: 4
id: 2psid: P102 fullname: пγ̼ƻ® userid: 3
id: 2psid: P102 fullname: пγ̼ƻ® userid: 2
×¢Òa£º´Ë½¨ÖÐµÄ in_array($need,$arr,$strict)
ÔÚ PHP °ae±¾ 4.2.0 ֮ǰ£¬$need ²»ÔÊÐiÊÇÒ»¸oÊý×e¡£$stric Ϊ true »aÑϸñȥƥÅa $need ºÍ $arr Öдý²eÕÒµÄÀaÐÍ
¸u¶a¹ØÓÚPHPÏa¹ØÄÚÈݸÐÐËȤµÄ¶ÁÕ߿ɲe¿´±¾Õ¾×¨Ìa£º¡¶PHPÊý×e(Array)²Ù×÷¼¼ÇÉ´oÈ«¡¡¢¡¶[phpÅÅÐoËa¨×ܽa](http://www.jb51.net/Special/150.htm)¡¡¢¡¶[php×Öu´®(string)Óè×ܽa](http://www.jb51.net/Special/47.htm)¡¡¢¡¶PHPÕe¶ÔXMLÎļþ²Ù×÷¼¼ÇÉ×ܽa¡¡¢¡¶[PHP´iÎoÓeÒi³£´¦Ài½¨×ܽa](http://www.jb51.net/Special/196.htm)¡¡¢¡¶PHPÔËËaÓeÔËËauÓè×ܽa¡¡¢¡¶[PHP»u±¾Ói¨ÈeÃŽ̳Ì](http://www.jb51.net/Special/348.htm)¡¡¢¡¶phpÃaeÏo¶ÔÏo³ÌÐoÉe¼ÆÈeÃŽ̡̳¡¢¡¶php+mysqlÊý¾Ý¿a²Ù×÷ÈeÃŽ̡̳¼°¡¶php³£¼uÊý¾Ý¿a²Ù×÷¼¼ÇÉ»a×Ü¡
Ï£Íu±¾ÎÄËuÊo¶Ô´o¼ÒPHP³ÌÐoÉe¼ÆÓÐËu°iÖu¡£