Home > php教程 > PHP源码 > Delete instances of removing identical elements and array duplicate values ​​in a two-dimensional array

Delete instances of removing identical elements and array duplicate values ​​in a two-dimensional array

大家讲道理
Release: 2016-11-08 11:27:32
Original
1174 people have browsed it

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 = 'stu_name';
$quchong = assoc_title($teachers, $key_title);
 
 
echo "<table border=\"1\" bordercolor=\"#CCCCCC\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse:collapse\" width=\"20%\">";
echo "<tr><td>id</td><td>学生名</td><td>电话</td></tr>";
$i = 1;
foreach ($quchong as $key => $vale) {
    if ($vale[&#39;stu_name&#39;] == "游开琳" or $vale[&#39;stu_name&#39;] == "韩建通") {
 
        continue;
    }
 
    echo "<tr><td>{$i}</td><td>{$vale[&#39;stu_name&#39;]}</td><td>{$vale[&#39;tel&#39;]}</td></tr>";
    $i++;
 
}
 
echo "</table>";
Copy after login

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template