Delete Remove duplicate value instances of same element and array in two-dimensional array

Source: Internet
Author: User

$list = Array (
Array (' ID ' =>107, ' title ' => ' AAA '),
Array (' ID ' =>106, ' title ' => ' BBB '),
Array (' ID ' =>105, ' title ' => ' CCC '),
Array (' ID ' =>104, ' title ' => ' CCC '),
Array (' ID ' =>103, ' title ' => ' DDD '),
Array (' ID ' =>102, ' title ' => ' eee '),
Array (' ID ' =>101, ' title ' => ' FFF '),

);


function Assoc_title ($arr, $key) {
$tmp _arr = Array ();
foreach ($arr as $k => $v) {
if (In_array ($v [$key], $tmp _arr)) {
Unset ($arr [$k]);
} else {
$tmp _arr[] = $v [$key];
}
}
return $arr;
}//assoc_title End
$key _title= ' title ';
Assoc_title ($list, $key _title);
Print_r ($list);

/*
Method II with Array_unique ()
The Array_unique () function shifts the duplicate values in the divisor group and returns an array of results. When the values of several array elements are equal, only the first element is preserved

*/
$sarray = Array (' 0 ', ' 111cn.net ', ' www.111cn.net ', ' 0 ');
$s = Array_unique ($sarray);
Print_r ($s);

/*
The result is
Array
(
[0] => 0
[1] => 111cn.net
[2] => www.111cn.net
)
*/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.