Maanu Posted November 24, 2014 Share Posted November 24, 2014 Hi, please help me to solve my query... I was incurring a problem in executing a PHP code which executes 'n' number of data sets.. For example -- in the below shown outputs, I need to eliminate executing the 4th output which is similar (repeated data) to the 1st output, input output 4,4,5,6,5 4,4,5,5,6 4,4,5,7,5 4,4,5,5,7 4,4,5,7,6 4,4,5,6,7 4,4,6,5,5 4,4,5,5,6 Kindly send me the function details to execute it without repetition. Thanks a lot for your support! Regards, Maanu Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 24, 2014 Share Posted November 24, 2014 How are we to do that when you haven't provided any code as to what you are doing now? Are you getting the data from a database, getting it from an external source, generating it yourself? All of these scenarios would require a different type of solution. Quote Link to comment Share on other sites More sharing options...
Maanu Posted November 24, 2014 Author Share Posted November 24, 2014 Thanks for your response.... I tried the following code but i executes only the partial set of data ... The data is given by myself..... function $dataset($mydataset , $array) { $array = array(); sort($mydataset); $data = array_unique($mydataset); foreach($array as $arr) { sort($arr); if(count(array_intersect($mydataset,$array)) == count($arr)) return true; } } Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 24, 2014 Share Posted November 24, 2014 Per the manual: Note: Note that array_unique() is not intended to work on multi dimensional arrays. In your function, I don't understand why you have a parameter for $array, but on the very first line you then define $array as an empty array - thereby overwriting any data that may have been passed in the function. I'm sure there are better solutions, but one approach would be to implode the data, sort it, then explode it back out. Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 24, 2014 Share Posted November 24, 2014 This seems to work for your scenario function filterMyDataset($mydataset) { //Create temp array to remove non-unique values and sort $tempArray = array(); foreach($mydataset as $subArray) { sort($subArray); $tempArray[] = implode(',', $subArray); } sort($tempArray); //Convert back to sub arrays for output $outputArray = array_unique($tempArray); foreach($outputArray as &$subArray) { $subArray = explode(',', $subArray); } return $outputArray; } Quote Link to comment Share on other sites More sharing options...
Maanu Posted November 25, 2014 Author Share Posted November 25, 2014 Thanks for your response.... I tried the following code but i executes only the partial set of data ... The data is given by myself..... function $dataset($mydataset , $array) { $array = array(); sort($mydataset); $data = array_unique($mydataset); foreach($array as $arr) { sort($arr); if(count(array_intersect($mydataset,$array)) == count($arr)) return true; } } This seems to work for your scenario function filterMyDataset($mydataset) { //Create temp array to remove non-unique values and sort $tempArray = array(); foreach($mydataset as $subArray) { sort($subArray); $tempArray[] = implode(',', $subArray); } sort($tempArray); //Convert back to sub arrays for output $outputArray = array_unique($tempArray); foreach($outputArray as &$subArray) { $subArray = explode(',', $subArray); } return $outputArray; } Thanks for your reply... The dataset was already sorted in order, so thing is that only i need remove the repeated dataset to occur only once... The datas has to be echo only at the end of program... so implode and explode i cant use it correctly... The function i need is that only to check duplicate dataset and in return it should delete it and occur only one set of data.... Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 25, 2014 Share Posted November 25, 2014 I tested the function before I posted it, so it does work. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.