How to Remove Duplicates From Multidimensional Array

PHP

Nicesnippets

3180

09-01-2020


Hi Guys

In this blog , I am today explain how to remove duplicate values from multidimensional array in php.you can easy to php get unique values from multidimensional array. we are destroyer duplicate values from multidimensional array in php

you can remove duplicates from multidimensional array by value in php.i can delete duplicates in multidimensional array example in php

Example 1

My PHP Multidimensional Array

Array

(

[0] => Array

(

[name] => PHP

)

[1] => Array

(

[name] => LARAVEL

)

[2] => Array

(

[name] => PHP

)

)

Remove duplicate Values

<?php

$myMultiArray = array(

array(

"name" => "PHP"

),

array(

"name" => "LARAVEL"

),

array(

"name" => "PHP"

)

);

$uniqueMyArray = array_map("unserialize", array_unique(array_map("serialize", $myMultiArray)));

echo "<pre>";

print_r($myMultiArray);

echo "</pre>"

?>

Output

Array

(

[0] => Array

(

[name] => PHP

)

[1] => Array

(

[name] => LARAVEL

)

)

Example 2

My PHP Multidimensional Array

Array

(

[0] => Array

(

[0] => Php

[1] => Laravel

)

[1] => Array

(

[0] => Html

[1] => Css

)

[2] => Array

(

[0] => Php

[1] => Laravel

)

)

Remove duplicate Values

<?php

$myMultiArray = [

['Php','Laravel'],

['Html','Css'],

['Php','Laravel'],

];

$uniqueMyArray = array_map("unserialize", array_unique(array_map("serialize", $myMultiArray)));

echo "<pre>";

print_r($myMultiArray);

echo "</pre>"

?>

Output

Array

(

[0] => Array

(

[0] => Php

[1] => Laravel

)

[1] => Array

(

[0] => Html

[1] => Css

)

)

it will help you..


Recommended Posts