-1

I have these arrays i want to remove remove duplicate links from my array how can i do this please help

I have many links in my array first array have no key and others have key all links have unique ids i want to remove same id links and submit it into mysql. all work is done now i am stuck in this duplicate issue please kindly help me.

 Array
    (
        [0] => mainlink

        [apple] => Array
            (
                [0] => http://apple1.to/getac/fdjpkb9xdixq
                [1] => http://apple1.to/getac/fdjpkb9xdixq
                [2] => http://apple1.to/getac/fdjpkb9xdixq
                [3] => http://apple2.to/getac/fdjpkb9xdixq
                [4] => http://apple2.to/getac/fdjpkb9xdixq
                [5] => http://apple2.to/getac/fdjpkb9xdixq
            )

       [banana] => Array
           (
                [0] => http://banana1.to/getac/fdjpkb9xdixq
                [1] => http://banana2.to/getac/fdjpkb9xdixq
                [2] => http://banana1.to/getac/fdjpkb9xdixq
                [3] => http://banana2.to/getac/fdjpkb9xdixq
           )


    )

Thanks.

I want this result:

 Array
    (
        [0] => mainlink

        [apple] => Array
            (
                [0] => http://apple1.to/getac/fdjpkb9xdixq
                [3] => http://apple2.to/getac/fdjpkb9xdixq
            )

       [banana] => Array
           (
                [0] => http://banana1.to/getac/fdjpkb9xdixq
                [1] => http://banana2.to/getac/fdjpkb9xdixq
           )


    )
Rizier123
  • 58,877
  • 16
  • 101
  • 156
Sufyan
  • 506
  • 2
  • 6
  • 18
  • `$array['apple'] = array_unique($array['apple']); $array['banana'] = array_unique($array['banana']);` – splash58 Jul 07 '15 at 11:53

1 Answers1

2

This should work for you:

Just loop through your array with array_map() and check if it is an array or not. If yes just return the unique array with array_unique(), else just return the value.

<?php

    $unique = array_map(function($v){
        if(is_array($v))
            return array_unique($v);
        return $v;
    }, $array); 

    print_r($unique);

?>
Rizier123
  • 58,877
  • 16
  • 101
  • 156