-1

I have an multidimensional array like this

 Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [url] =>  http://www.youtube.com/watch?v=eJOiKuVeXA0
                    [title] => Title
                )

        )

    [1] => Array
        (
            [0] => Array
                (
                    [url] => https://www.youtube.com/watch?v=KhF2R0m0N6I
                    [title] => Demo video Name
                )

            [1] => Array
                (
                    [url] => https://www.youtube.com/watch?v=oB1CUxX1JJE
                    [title] => second video
                )

        )

    [2] => Array
        (
            [0] => Array
                (
                    [url] => https://www.youtube.com/watch?v=-D7VOPdAQfg
                    [title] => Title
                )

        )

    [3] => Array
        (
            [0] => Array
                (
                    [url] => http://www.youtube.com/watch?v=eJOiKuVeXA0
                    [title] => Title
                )

        )

    [4] => Array
        (
            [0] => Array
                (
                    [url] => https://www.youtube.com/watch?v=xAx2gc-zqzg&feature=player_detailpage
                    [title] => Title
                )

        )

    [8] => Array
        (
            [0] => Array
                (
                    [url] => https://www.youtube.com/watch?v=FVpmjX1DjmI
                    [title] => Title
                )

        )

    [10] => Array
        (
            [0] => Array
                (
                    [url] =>  http://www.youtube.com/watch?v=eJOiKuVeXA0
                    [title] => one
                )

        )

    [12] => Array
        (
            [0] => Array
                (
                    [url] => http://www.youtube.com/watch?v=eJOiKuVeXA0
                    [title] => Title
                )

            [1] => Array
                (
                    [url] =>  https://www.youtube.com/watch?v=-D7VOPdAQfg
                    [title] => Title
                )

        )

    [14] => Array
        (
            [0] => Array
                (
                    [url] =>  http://www.youtube.com/watch?v=eJOiKuVeXA0
                    [title] => Title
                )

            [1] => Array
                (
                    [url] => https://www.youtube.com/watch?v=-D7VOPdAQfg
                    [title] => Title
                )

        )

)

I am not able to remove multiple url values Want to remove duplicate url values... How to remove duplicate multidimensional array?

forgivenson
  • 4,394
  • 2
  • 19
  • 28
vignesh.D
  • 766
  • 4
  • 18

2 Answers2

1

I guess you need this function:

 function super_unique($array)
    {
      $result = array_map("unserialize", array_unique(array_map("serialize", $array)));

      foreach ($result as $key => $value)
      {
        if ( is_array($value) )
        {
          $result[$key] = super_unique($value);
        }
      }

      return $result;
    }

    $a = [['foo', 'bar'], ['foo', 'bar'], ['foo', 'bar_foo']];

    print_r(super_unique($a));

Outcome is:

Array
(
    [0] => Array
        (
            [0] => foo
            [1] => bar
        )

    [2] => Array
        (
            [0] => foo
            [1] => bar_foo
        )

)
B001ᛦ
  • 2,036
  • 6
  • 23
  • 31
-1

As the array is multidimensional you will need to loop through the items, and keep a list of which video URLs you have, and create a new array containing only the unique items, for example:

$unique_video_urls = array();
foreach($array as $id => $subarray) {
    foreach($subarray as $video) {
        if(!in_array($video['url'], $unique_video_urls)) {
            $unique_video_urls[] = $video['url'];
            $new_array[$id][] = $video;
        }
    }
}

$array is your original array.

In this example $new_array should look like your original array, but only containing unique items. The array keys from the original array have been retained, assuming they have some meaning to you?

Hopefully this is a starting point for you to use to process the array as you need.

jones
  • 346
  • 2
  • 11