inconsistency in converting string to integer, when string is hex, prefixed with '0x'

前端 未结 3 433
轻奢々
轻奢々 2021-01-14 05:44

Using PHP 5.3.5. Not sure how this works on other versions.

I\'m confused about using strings that hold numbers, e.g., \'0x4B0\' or \'1.2e3\'

3条回答
  •  再見小時候
    2021-01-14 06:23

    intval uses strtol which recognizes oct/hex prefixes when the base parameter is zero, so

    var_dump(intval('0xef'));     // int(0)
    var_dump(intval('0xff', 0));  // int(255)
    

提交回复
热议问题