Home > Backend Development > PHP Problem > How to delete duplicate arrays in php two-dimensional array

How to delete duplicate arrays in php two-dimensional array

藏色散人
Release: 2023-02-26 19:56:01
Original
2776 people have browsed it

How to delete duplicate arrays in php two-dimensional array

#How to delete duplicate arrays from a two-dimensional array?

The code is as follows:

//二维数组去掉重复值
 public function a_array_unique($array){
  $out = array();
 
  foreach ($array as $key=>$value) {
   if (!in_array($value, $out)){
    $out[$key] = $value;
   }
  }
 
  $out = array_values($out);
  return $out;
 }
Copy after login

Related introduction:

in_array() function searches whether the specified value exists in the array.

Note: If the search parameter is a string and the type parameter is set to TRUE, the search is case-sensitive.

Syntax

in_array(search,array,type)
Copy after login

Parameters

search Required. Specifies the value to search for in the array.

array Required. Specifies the array to search.

type Optional. If this parameter is set to true, it is checked whether the type of the searched data and the value of the array are the same.

Description

Returns true if the given value search exists in the array array. If the third parameter is set to true, the function returns true only if the element exists in the array and has the same data type as the given value.

If the parameter is not found in the array, the function returns false.

Note: If the search parameter is a string and the type parameter is set to true, the search is case-sensitive.

For more PHP related knowledge, please visit PHP Chinese website!

The above is the detailed content of How to delete duplicate arrays in php 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