I tried to trim my question, but this is the best I could do. Since I guess it's pretty hard to figure out what I need, I will give an example:
Let's say I have the following array:
$var = array( array(1, 2, 3), array(1, 3), array(1, 2, 4, 3), array(1, 3, 4) );
I want to remove all arrays from $var
, for which the first and last elements coincide with another array from $var
, but have more elements than the last.
So, you should remove the following arrays: (1, 2, 3)
and (1, 2, 4, 3)
, because they start with 1
and end with 3
and have more elements than (1, 3)
, which also starts and ends at 1
and 3
. (1, 3, 4)
must remain because there is no other array that starts at 1
and ends at 4
and has fewer elements than it.
I am looking for the most effective way to do this, both in terms of memory and in time. $var
can have up to 100 arrays, and each individual array can contain up to 10 elements. I was thinking of using some sort of comparison between all two elements ( for(i=0;...) for(j=i+1;...) complexCompareFunction();
), but I believe that this is not very efficient.