php三维数组去重(示例代码)_PHP

WBOY
Release: 2016-06-01 11:57:40
Original
824 people have browsed it

假设叫数组 $my_array;
复制代码 代码如下:
// 新建一个空的数组.
$tmp_array = array();

$new_array = array();

// 1. 循环出所有的行. ( $val 就是某个行)
foreach($my_array as $k => $val){

    $hash = md5(json_encode($val));
    if (in_array($hash, $tmp_array)) {
        echo('这个行已经有过了');
    }else{
        // 2. 在 foreach 循环的主体中, 把每行数组对象得hash 都赋值到那个临时数组中.
        $tmp_array[] = $hash;
        $new_array[] = $val;
    }
}

print_r($new_array);

$new_array 即为筛选后无重复数据的数组。

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!