PHP realizes the method of deleting the same elements and duplicate values ​​in the array in the two-dimensional array

墨辰丷
Release: 2023-03-27 14:18:01
Original
1925 people have browsed it

This article mainly introduces the method of PHP to delete the same elements in the two-dimensional array and the duplicate values ​​​​of the array, involving PHP's array traversal, judgment, comparison and other related operation skills. Friends in need can refer to it

The example in this article describes the method of PHP to delete the same elements and duplicate values ​​in the array in a two-dimensional array. Share it with everyone for your reference, the details are as follows:

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

## Related recommendations:

How to use the explode() function in PHP to cut a string into an array

PHP implements the method of calculating the frequency of words in a file or array

phpBasic learning: PHP Array and data structure

##

The above is the detailed content of PHP realizes the method of deleting the same elements and duplicate values ​​in the array in the two-dimensional array. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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