Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to remove words which occurs mutliple times in a string using PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 483
    Comment on it

    Hello Reader's If you have a string with words occurs more than two times then here you can see how to remove them as a single.

    Lets see the string below full of random words and 34 is repeating.

    $mystring = '2,34,two,findnerd,logic,66,34,55,blog';
    

    Now we will process the string in two phase. phase 1 explode the string and phase 2 select only index value(Unique Values)

    $MystringNoRepeat = implode(',',array_unique(explode(',', $mystring )));
    

    Here first use of array_unique to get all the unique values and second implode function will concatenate them into a single string named as, $MystringNoRepeat.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: