I have to compare elements in an array, apart from the first and last they are compared to their immediate neighbours.
If they fail the test, I have to remove the chosen item completely from the array, then start the comparison running again, minus the missing one.
I can get rid of an element with unset, but how to I reset the array again, so that all the values stay in order, but I make up the missing key?
Heres a contrived but simple example, lets say that if the difference between the preceding and following values is more than 19, it must be removed.
$test = array(
0=>111, // ok, its the first one
1=>110, // ok
2=>120, // bad!
3=>130, // bad!
4=>150, // ok, its the last one
);
The first iteration runs and key #1 is good, the diff between 111 and 120 is only 9.
The second iteration runs and key #2 is singled out as being bad, and unset()
Which leaves me:
$test = array(
0=>111, // ok
1=>110, // ok
3=>130, // bad!
4=>150, // ok
);
I was working on the principle of using a $ctr and just assessing 3 items at a time, but I need to reset the array at this point in order to make my assessment again - or do I?
At the moment I am trying to work out how to get this after the first iteration:
$test = array(
0=>111, // ok
1=>110, // ok
2=>130, // bad!
3=>150, // ok
);
I thought there was a sort function which drops key values, but cannot find one.
I can think of ways round this, but just thought I’d ask here.