utdiscant Posted December 7, 2006 Share Posted December 7, 2006 I made this code to remove all the duplicates from two arrays:I am putting the values which only exist once into an other array. I only need to check about the $xcoords cause i am just interested in removing duplicated x-coordinates:$position=0;for($i=0;$i<sizeof($xcoords_temp);$i++) { $found = 0; for($n=0;$n<$position;$n++) if($xcoords_temp[$i] == $xcoords[$n]) $found = 1; if($found == 0) { $xcoords[$position] = $xcoords_temp[$i]; $ycoords[$position] = $ycoords_temp[$i]; $position++; }}If you this code the inputs:$xcoords_temp = array(1,1,1,2,2,2);$ycoords_temp = array(2,2,2,1,1,1);It will generate the output:1 22 12 1Which is wrong because i only want:1 22 1What is wrong with my code?David Kofoed WindDenmark Link to comment https://forums.phpfreaks.com/topic/29840-removing-duplicates-from-array-doesnt-work/ Share on other sites More sharing options...
kenrbnsn Posted December 7, 2006 Share Posted December 7, 2006 Do you know about the [url=http://www.php.net/array_unique]array_unique()[/url] function?Ken Link to comment https://forums.phpfreaks.com/topic/29840-removing-duplicates-from-array-doesnt-work/#findComment-137090 Share on other sites More sharing options...
utdiscant Posted December 7, 2006 Author Share Posted December 7, 2006 It is indeed a nice function, but i need to remove the values from the $ycoords that have the same index as the ones i remove from $xcoords, is there an easy way to do that? Link to comment https://forums.phpfreaks.com/topic/29840-removing-duplicates-from-array-doesnt-work/#findComment-137091 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.