Home >Backend Development >PHP Tutorial >PHP array deduplication function code_PHP tutorial

PHP array deduplication function code_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:13:211142browse

Copy code The code is as follows:

function assoc_unique($arr, $key) {
$ tmp_arr = array(); $k]);                                                                                  arr);
return $arr;
}

$aa = array(
array('id' => 123, 'name' => 'Zhang San'),
array('id' => ; 123, 'name' => '李思'),
array('id' => 124, 'name' => '王五'),
array('id' => ; 125, 'name' => 'Zhao Liu'),
array('id' => 126, 'name' => 'Zhao Liu')
);
$key = 'name';
assoc_unique(&$aa, $key);
print_r($aa);
?>





http://www.bkjia.com/PHPjc/326485.html

www.bkjia.com
true

http: //www.bkjia.com/PHPjc/326485.html

Copy the code as follows: ?php function assoc_unique($arr, $key) { $tmp_arr = array(); foreach($arr as $k = $v) { if(in_array($v[$key], $tmp_arr)) { unset($arr[$k]); } else { $tmp...
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