dr5779 2015-03-18 10:30
浏览 93
已采纳

字母数字字符串和php运算符(zipcode)

I have over 3500 small strings called "Forward sortation areas". They are the first three digits of canadian zipcodes. They follow a logical alphanumerical order.

Exemple: H2W, H2X, H2Y, H2Z, H3A, H3B etc..

I need to define a "pricelevel" value for those FSAs in an if/else statement, and luckily, they go a big bunch at a time. What i'm trying to do is something like this:

$fsa = "H2V" ;

if ($fsa >= "H2A" and <= "H2R") {
$pricelevel = "1";
} elseif ($fsa >= "H2S" and <= "H3B") {
$pricelevel = "2";
} elseif ($fsa >= "H3C" and <= "H4M") {
$pricelevel = "3";
}

In this case, $pricelevel would be "2".

If i'm not mistaking it's impossible to use these operators on alphanumerical strings. There's got to be a way of doing this but i cant figure out. Thanks in advance for your precious help.

  • 写回答

1条回答 默认 最新

  • dongsuoxi1790 2015-03-18 10:37
    关注

    Yes, PHP will translate those strings to numbers, if on both sides of comparison there is a string.

    However you have a bug here - after and you have to put $fsa again:

    if ($fsa >= "H2A" and $fsa <= "H2R") {
    

    You can read about it here: http://php.net/manual/en/language.operators.comparison.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ESP8266连接阿里云出现问题
  • ¥15 被蓝屏搞吐了,有偿求帮解答,Ai回复直接拉黑
  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并