You are viewing this forum as a guest. Login to an existing account, or create a new account, to reply to topics and to create new topics.
Hi
In my customised shipping method I have the following:
elseif ((substr($postcode, 0, 2) == "PL")||(substr($postcode, 0, 2) == "TR")||(substr($postcode, 0, 2) == "EX")||(substr($postcode, 0, 2) == "TQ")||(substr($postcode, 0, 2) == "TA"))
{ Do this }where I'm trying to find if the customer lives in our nearby postal areas. My php coding is not the best, as you can see, and I use long-winded coding to get my result.
Is there a cleaner way of writing the above code to get the same result?
Many thanks
Terry
Offline
I think I might have answered my own question!
I have discovered in_array() which would mean the statement would become:
(in_array(substr($postcode, 0, 2), array("PL", "TR", "EX", "TQ", "TA")))This obviously looks much neater, I'll just need to make sure it works!
Terry
Offline
That's more complex than I would have written it, but it does the job. I would have done a simple preg_match:
if (preg_match('/^(PL|TR|EX|TQ|TX)/',$postcode)) {$do_something = 1;}Offline