I am trying to show echo 2 but its not working
$zipcode1 = 07300-011; $zipcode= str_replace("-","",$zipcode1); $zipcode = 07300011; if ($zipcode >= 20000000 && $zipcode <= 26600999) { echo '1'; } elseif ($zipcode >= 07000001 && $zipcode <= 07399999) { echo '2'; } else { echo 'no value'; }
Please let me know where i am doing wrong. Thank you for the help Result = 2
Advertisement
Answer
You need to compare string with string if the leading 0 of the zipcode is important:
$zipcode1 = "07300-011"; $zipcode= str_replace("-","",$zipcode1); $zipcode = "07300011"; if ($zipcode >= "20000000" && $zipcode <= "26600999") { echo '1'; } elseif ($zipcode >= "07000001" && $zipcode <= "07399999") { echo '2'; } else { echo 'no value'; }