douna1941 2015-02-12 16:20
浏览 81
已采纳

php is_numeric零填充字符串(0000018)

I have tested is_numeric on zero filled ints such 0000018 and it return true. The documentation says:

"Finds whether the given variable is numeric. Numeric strings consist of optional sign, any number of digits, optional decimal part and optional exponential part. Thus +0123.45e6 is a valid numeric value. Hexadecimal (e.g. 0xf4c3b00c), Binary (e.g. 0b10100111001), Octal (e.g. 0777) notation is allowed too but only without sign, decimal and exponential part."

Would this fall under the any number of digits part?

  • 写回答

2条回答 默认 最新

  • duanji5569 2015-02-12 16:30
    关注

    Both cases (string and the (invalid)octal number) will return true:

    var_dump( is_numeric("0000018") );  //bool(true)
    var_dump( is_numeric(0000018) );    //bool(true)
    

    In the first case it's just a numeric string.

    A quote from the manual (is_numeric()):

    Returns TRUE if var is a number or a numeric string, FALSE otherwise.

    In the second case it is a octal number, just a invalid one, so this will happen (From the manual Integer):

    Warning: If an invalid digit is given in an octal integer (i.e. 8 or 9), the rest of the number is ignored.

    Means in this case:

    0000018 -> 000001 -> 1
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题