How to Remove Duplicates From Multidimensional Array in PHP?
In this post, you can remove duplicates from multidimensional array by value in php.
1. Code:
<?php function getUniqueMultiArray($multiArray){ $uniqueMyArray = array_map("unserialize", array_unique(array_map("serialize", $multiArray))); return $uniqueMyArray; } $multiArray = array( array( "name" => "PHP" ), array( "name" => "LARAVEL" ), array( "name" => "PHP" ) ); echo "<pre>"; print_r(getUniqueMultiArray($multiArray)); echo "</pre>" ?>
2. Example:
Input:
$multiArray = array( array( "name" => "PHP" ), array( "name" => "LARAVEL" ), array( "name" => "PHP" ) );
Output:
Array ( [0] => Array ( [name] => PHP ) [1] => Array ( [name] => LARAVEL ) )