简体   繁体   中英

What does the '0x0'. do in this equation $intTotal += '0x0'.$value;

Sorry I am new to php and am getting very confused on a bit of code I am working on.

So I get that intTotal += $value; would just add the value to the intTotal but how does the $intTotal += '0x0'.$value; works? I am getting all sorts of random differences when I chance the 0x0 to something else as well.

Thanks

$value is apparently a string representing a number in hexadecimal.

The string concatenation (the . operator) prefixes it with 0x0 , the 0x prefix is used to denote a hexadecimal number (the extra zero is superfluous).

So for example if $value = "f" , this will produce 0x0f . This will then be converted to the integer 15 by PHP, and added to $intTotal .

0x0只是十六进制表示形式的常规0,与变量语法一起使用时,该类型会转换为字符串'0'

$intTotal += '0x0'.$value; converts $value from hexadecimal number in string to format usable by php and then adds it to $intTotal (after typecasting from string to int).

Edited to add clarity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM