Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Apr 2010
    Posts
    121
    Thanks
    6
    Thanked 0 Times in 0 Posts

    How do you find ONLY unique strings in an array?

    I have a list of 4000 web addresses. I need to extract all the web addresses that only occur once. Any that are in the list twice or more I don't want to know about.

    How do you extract unique strings?

    Thanks
    Mike

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    PHP Code:
    <?php
    $input 
    = array("a" => "green""red""b" => "green""blue""red");
    $result array_unique($input);
    print_r($result);
    ?>
    The above example will output:

    Array
    (
    [a] => green
    [0] => red
    [1] => blue
    )
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #3
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,389
    Thanks
    13
    Thanked 353 Times in 349 Posts
    @arctic: I think he meant not to exclude duplicate values, but to find values that that are present once and only once.

    array_count_values() (and array_filter()) should be what you’ll need.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •