Splitting an array and doing tests

Refresh

April 2019

Views

12 time

0

I have a little problem, so I receive number's and I store them in an array to do some tests. I test firstly their succession with this method

 $range = range($last_index, max($this->tab));
 $missing_numbers = array_diff($range, $this->tab);

and secondly I test the redundancy of those number's like this

if(in_array($this->tab, $received_number)){
 array_push($tab_error, $received_number);
}

For example, for this array there's 2 errors : missing (1) and redundant (2)

  Array ( 
        [0] => 0 
        [1] => 2
        [2] => 2
    )

The problem is I have a max_number If I go beyond it, I have to repeat the test again and not include it with the old one

For example here I suppose that my Max is 5, and I have this array :

  Array ( 
        [0] => 0 
        [1] => 1
        [2] => 3
        [3] => 4
        [4] => 5  // <-- The max 
        [5] => 1 
        [6] => 2
        [7] => 4
    )

Here I must have only two errors about the missing (2) and the the missing (3) in the second part of the array after the max, and not the error about the redundancy of the numbers. Maybe I have to split the array but I don't know what's the best method to re-check it.

Thank you!

0 answers