You appear to be a bot. Output may be restricted
Description
Determine if now is closer to wanted than the best so far- = perfect – this is the exact value
- = better – the new value is better than best so far
- = it's a start – well at least it's not 0
- = same – the new value is the same as the best so far, but it's not the wanted value
- = worse – the new value is not as good as the best so far
$best | $now | result |
---|---|---|
0 | w/y/z | 2 = it’s a start |
0 | x | 9 = perfect |
w | w | 1 = same |
w | x | 9 = perfect |
w | y/z | 3 = better |
x | w | 0 = worse |
x | x | 9 = perfect |
x | y/z | 0 = worse |
y | w | 0 = worse |
y | x | 9 = perfect |
y | y | 1 = same |
y | z | 0 = worse |
z | w | 0 = worse |
z | x | 9 = perfect |
z | y | 3 = better |
z | z | 1 = same |
Usage
$integer = bw_closer( $wanted, $best, $now );
Parameters
- $wanted
- ( integer ) required – the exact value we want to match
- $best
- ( integer ) required – the best value so far
- $now
- ( integer ) required – the current value
Returns
integer $result – one of the aboveSource
File name: oik-nivo-slider/nivo.phpLines:
1 to 22 of 22
function bw_closer( $wanted, $best, $now ) { if ( $wanted == $best ) { if ( $now == $best ) { $result = 9; } else { $result = 0; } } elseif ( $now == $wanted ) { $result = 9; } elseif ( $best == 0 ) { $result = 2; } elseif ( ( $best < $wanted ) && ( $now > $wanted ) ) { $result = 3; } elseif ( ( $now < $best ) && ( $now > $wanted) ) { $result = 3; } elseif ( $now == $best ) { $result = 1; } else { $result = 0; } return( $result ); }View on GitHub View on Trac