FD_F Posted June 20, 2009 Share Posted June 20, 2009 here is my code any advice what i`m doing wrong ? $str = "the brown fox jumped over the white fox"; $NewStr = split(" ", $str); $flag = 0; foreach($NewStr as $me) { foreach($NewStr as $check) { if($me == $check) { $flag++; if($flag <= 1) { $arr[] = $check; } } } $flag = 0; } var_dump($arr); output shuld be the brown fox jumped over white Link to comment https://forums.phpfreaks.com/topic/163034-solved-need-help-with-making-function-like-array_unique/ Share on other sites More sharing options...
phant0m Posted June 20, 2009 Share Posted June 20, 2009 what's wrong with array_unique? if you want to reindex the array, use array_values Link to comment https://forums.phpfreaks.com/topic/163034-solved-need-help-with-making-function-like-array_unique/#findComment-860203 Share on other sites More sharing options...
FD_F Posted June 20, 2009 Author Share Posted June 20, 2009 its for practice Link to comment https://forums.phpfreaks.com/topic/163034-solved-need-help-with-making-function-like-array_unique/#findComment-860205 Share on other sites More sharing options...
fnairb Posted June 20, 2009 Share Posted June 20, 2009 Quick and dirty, use an associative array. <?php $str = "the brown fox jumped over the white fox"; $NewStr = split(" ", $str); $uniq = array(); foreach($NewStr as $me) { $uniq[$me] = 1; } var_dump(array_keys($uniq)); ?> Link to comment https://forums.phpfreaks.com/topic/163034-solved-need-help-with-making-function-like-array_unique/#findComment-860251 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.