Home >Backend Development >PHP Tutorial >How to remove duplicate values from multidimensional array in PHP?
During the development of PHP projects, sometimes we need to remove duplicate values from multi-dimensional arrays in PHP frameworks, such as laravel, codeigniter and zend, etc. Below, we will introduce to you how to delete duplicate values from PHP multi-dimensional arrays with specific examples.
In the example below, there is a simple multi-dimensional array with repeated values, then we can pass PHP array_map() and The array_unique() function is used to obtain unique values from multi-dimensional arrays, that is, to remove duplicate values from multi-dimensional arrays.
PHP Multidimensional Array:
Array ( [0] => Array ( [0] => php [1] => sql ) [1] => Array ( [0] => javascript [1] => c ) [2] => Array ( [0] => php [1] => sql ) [3] => Array ( [0] => c++ [1] => java ) )
Remove duplicate values:
$myArray = Array( Array('php','sql'), Array('javascript','c'), Array('php','sql'), Array('c++','java') ); $myArray = array_map("unserialize", array_unique(array_map("serialize", $myArray))); print_r($myArray);
Output:
Array ( [0] => Array ( [0] => php [1] => sql ) [1] => Array ( [0] => javascript [1] => c ) [3] => Array ( [0] => c++ [1] => java ) )
Related recommendations: "PHP Tutorial"
This article is about the method of deleting duplicate values from PHP multi-dimensional arrays. It is simple and easy to understand. I hope Help those in need!
The above is the detailed content of How to remove duplicate values from multidimensional array in PHP?. For more information, please follow other related articles on the PHP Chinese website!