123123
V2EX  ›  PHP

MySQL 中使用 SELECT IFNULL(xxx, 0) AS 'yyy' 返回值类型问题

  •  
  •   123123 · May 1, 2013 · 5084 views
    This topic created in 4808 days ago, the information mentioned may be changed or developed.
    如果字段是空值这样返回的 0 的类型是 string,除了在 PHP 端遍历结果集去写 (int) 以外,有没有什么更好的办法让返回值的类型是 int
    4 replies    1970-01-01 08:00:00 +08:00
    soonlai
        1
    soonlai  
       May 2, 2013
    PHP 的变量是没有类型的,如果比较 ‘0’ == 0 就是相等,不需要强制转换。
    123123
        2
    123123  
    OP
       May 2, 2013
    @soonlai 但是用作 API 返回值 json_encode 后 其他语言是有类型检查的
    soonlai
        3
    soonlai  
       May 2, 2013
    javascript 比较 '0' == 0 也是相等的,是不是你是在 decode 的时候异常了,这就需要转换了。
    123123
        4
    123123  
    OP
       May 3, 2013
    @soonlai 不是,有些插件比如 highchart 如果数据类型不是 int 就不会正常的显示结果
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   967 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 19:37 · PVG 03:37 · LAX 12:37 · JFK 15:37
    ♥ Do have faith in what you're doing.