简体   繁体   English

在 PHP 中为变量分配数值

[英]Assigning numeric values to variables in PHP

I am trying to assign a variable the value of 01234 using PHP.我正在尝试使用 PHP 为变量分配01234的值。 But it keeps coming up with a different number.但它不断提出不同的数字。 Why is it is displaying 668 ?为什么显示668

$data = 01234;
echo $data;

The result I am getting is: 668我得到的结果是: 668

From the manual :从手册

Integers can be specified in decimal (base 10), hexadecimal (base 16), octal (base 8) or binary (base 2) notation, optionally preceded by a sign (- or +).整数可以用十进制(基数 10)、十六进制(基数 16)、八进制(基数 8)或二进制(基数 2)表示法指定,可以选择在前面加上符号(- 或 +)。

[...] [...]

To use octal notation, precede the number with a 0 (zero) .要使用八进制表示法,请在数字前面加上 0(零) To use hexadecimal notation precede the number with 0x.要使用十六进制表示法,请在数字前加上 0x。 To use binary notation precede the number with 0b.要使用二进制表示法,请在数字前加上 0b。

You mistakenly specified the octal number 1234 (by adding the zero prefix) which equals 668 decimal.您错误地指定了等于十进制668的八进制数1234 (通过添加零前缀)。

Having a leading zero is an instruction to parse it as an octal number, As having 0x as prefix means hex.前导零是将其解析为八进制数的指令,因为以 0x 作为前缀表示十六进制。 See the documentation for more information .有关详细信息,请参阅文档

So this 01234 is parsed as octal and converted to decimal value which is 668.所以这个 01234 被解析为八进制并转换为十进制值 668。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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