The error you where getting was because og the way you where doing the comparisons.
in this line:
if (($min %2 = 0 AND $max %2 = 0) OR ($min %2 != 0 AND $max %2 != 0)) {
this code is setting the result:
$min %2 = 0
to do an equals comparison in PHP, it should be:
$min %2 == 0
so that line should be:
if (($min %2 == 0 AND $max %2 == 0) OR ($min %2 != 0 AND $max %2 != 0)) {