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

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

报告相同问题?

悬赏问题

  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?