Use of || (or)
I got so many values which I need to compare with same variable, is there a better way to write more efficiently such as $city == -35 || -34 || -33 or even simpler so that I don't have to repeat variable name since it's the same variable only value keep changing.
<?php
if ($city == -35 || $city == -34 || $xcity == -33)
{
$region = "noindex";
}
?>
Any suggestions?
You might use in_array()
if (in_array($city, array(-35, -34, -33))) {
$region = "noindex";
}
Or if they are consecutive ( I suspec they aren't and this is just an example)
in_array($city, range(-35, -33))
Yes. Use in_array,
in_array($city, array(-35,-34,-33))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With