How to remove a variable value from an array

Hi All
I’m sorting an array to get the lowest value and highest as below but want to exclude a set value ie 99. How could I do this ?

$min = min(array($monStart, $tuesStart, $wedStart ,$thursStart, $friStart, $satStart, $sunStart));
$max = max(array($monFinish, $tuesFinish, $wedFinish ,$thursFinish, $friFinish, $satFinish, $sunFinish));

Many thanks


Have a look at array_diff(). You’ll need to make another array of the “exclude” values.

Or, array_search() with [URL=“”]unset() if you have just one value to exclude (but the above will also work for that case).

Cheers Mate, I have a look. Thanks for the quick reply :slight_smile:

or since 99 is the highest value in your list (from previous thread), you could just modulo all values in the max array by 99, which would reduce any such entry to being 0, and thus not the max.

Note that this only works because 99 is the highest value.

Only problem with that is you can no longer tell the difference between 0 and 99. So if you values are 0, 0, 0, 1, 99, you have 0, 0, 0, 1, 0. You may include the 99 result even though now it is rated as 0.

It doesn’t have to be 99, I am using a 24 hour clock for hours available each day and have set 99 as a closed day, but need to exclude this number as it will always show as the highest

Depends on your values. If the max must be in the range [0…98] and all values are 99, the failover would be 0.

Keep in mind that the request was made on a MAX. max of 0,0,0,1,99 excluding 99’s, and 0,0,0,1,0 are the same - 1.

My bad, I thought this was in relation to I got confused. If it were in relation, then my statement would still hold true, but if it isn’t you are correct that 0,0,0,1,0 is the same as excluding the 99 and only having 0,0,0,1 in the range.