dcole.ath.cx Posted June 17, 2006 Share Posted June 17, 2006 What script could I use to remove parts of an array if it's repeated?like$test = "I wish I was a moderator. I wish I was a bus driver. I love smiles!$data = explode(" ", $test);SOMETHING---then the new array would be: I, wish, was, a, moderator, bus, driver, love, smiles!As you can see the repeat of a word was taken out. Link to comment Share on other sites More sharing options...
srinivasan Posted June 17, 2006 Share Posted June 17, 2006 I believe this code may suit your requirements.-------------------------------------------------------------------------------------------$test = "I wish I was a moderator. I wish I was a bus driver. I love smiles!";$data = explode(" ", $test);$count = count($data);$newdata = array();for($i=0; $i<$count; $i++){ $value = $data[$i]; if(!in_array($value, $newdata)) { $value = explode(".", $value); $newdata[] = $value[0]; }}echo print_r($newdata);-------------------------------------------------------------------------------------------Regardssrinivasan and suresh (Team Crew)India - Tamilnadu Link to comment Share on other sites More sharing options...
justsomeguy Posted June 17, 2006 Share Posted June 17, 2006 That code works. But you don't need to do an echo before print_r, print_r does not return anything, it just sends it straight to output. Just writing print_r is enough to see the array.But that's beside the point, that code does work. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now