stevewhea — 2012-05-16T13:40:12-04:00 — #1
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));
qmonkey — 2012-05-16T14:16:29-04:00 — #2
Have a look at array_diff(). You'll need to make another array of the "exclude" values.
Or, [array_search() with [URL="http://php.net/unset"]unset()](http://php.net/array_search) if you have just one value to exclude (but the above will also work for that case).
stevewhea — 2012-05-16T14:21:29-04:00 — #3
Cheers Mate, I have a look. Thanks for the quick reply
starlion — 2012-05-16T14:35:37-04:00 — #4
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.
cpradio — 2012-05-16T14:43:55-04:00 — #5
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.
stevewhea — 2012-05-16T14:59:02-04:00 — #6
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
starlion — 2012-05-16T21:41:31-04:00 — #7
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.
cpradio — 2012-05-17T07:42:16-04:00 — #8
My bad, I thought this was in relation to http://www.sitepoint.com/forums/showthread.php?854127-Find-Highest-And-Lowest-Values-Of-Variables-In-Form-Post. 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.