How to Remove Duplicates From Multidimensional Array

Share Me
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Today now in this blog , I will explain with you how to remove duplicate values from multidimensional array in php . we can easy to php get unique values from a multidimensional array. So we can destroyer duplicate values from any multidimensional array in php

So we can remove any duplicates from multidimensional array by value in php. Now here i will 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
        )
)

Read Also : Laravel 8 Eloquent Global Scope Tutorial Example

I hope it will help you. Also you can follow us on Facebook

About code chef

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by code chef →