SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist silversurfer5150's Avatar
    Join Date
    Aug 2010
    Posts
    534
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    CHeck array to see if element occurs twice

    Ok guys, what I want to do basically is I have an array of strings and each one will render an image on the screen. However, if a string appears more than once in the array which is possible, it will render multiple times on the screen. How do I scan the array to see if any two or more strings are the same and if so stop it rendering?
    thanks
    "Persistence is the path to perfection"

  2. #2
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in_array() function checks if the same value already exists and array_unique() function returns the unique values of array. See the examples in the respective functions manual page.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  3. #3
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)
    silversurfer5150 use:
    PHP Code:
    $array_with_duplicates = array('one''one''two''two');
    print_r($array_with_duplicates); echo'<br />';
    $no_dupes_array =array_unique($array_with_duplicates);print_r($no_dupes_array); echo'<br />'
    Outputs:

    Code:
    Array ( [0] => one [1] => one [2] => two [3] => two ) 
    Array ( [0] => one [2] => two )
    Steve

    ictus==""

  4. #4
    SitePoint Evangelist silversurfer5150's Avatar
    Join Date
    Aug 2010
    Posts
    534
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey thanks so much both,
    really appreciate it
    "Persistence is the path to perfection"


Bookmarks

Posting Permissions

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