php – 为什么$variable = 0759给出61?

栏目: PHP · 发布时间: 7年前

内容简介:参见英文答案 >我不知道如何谷歌这一个,所以我在这里问.当我宣布一个变量$something = 0759变成61时,为什么会发生这种情况.我知道答案必须非常简单,所以请原谅我的愚蠢.翻译自:https://stackoverflow.com/questions/22040815/why-does-variable-0759-give-out-61

参见英文答案 > What does a leading zero do for a php int? 4个

我不知道如何谷歌这一个,所以我在这里问.当我宣布一个变量$something = 0759变成61时,为什么会发生这种情况.我知道答案必须非常简单,所以请原谅我的愚蠢.

它是一个Integer字面值,您声明一个前导零的八进制数字.

$something = 0759; // octal

八进制数字系统是base-8数字系统.

您只能使用0-7之间的数字(其他数字将被丢弃).

$a = 0759; 
$b = 075;
var_dump($a==$b);
// bool(true)

http://www.php.net/manual/en/language.types.integer.php

你可以用ltrim跳过零.

$a = ltrim("0759", 0); 
 echo $a; // 759
 // and reformat as suggested with str_pad or printf
 echo str_pad($a, 4, "0", STR_PAD_LEFT);

翻译自:https://stackoverflow.com/questions/22040815/why-does-variable-0759-give-out-61


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Numerical Recipes 3rd Edition

Numerical Recipes 3rd Edition

William H. Press、Saul A. Teukolsky、William T. Vetterling、Brian P. Flannery / Cambridge University Press / 2007-9-6 / GBP 64.99

Do you want easy access to the latest methods in scientific computing? This greatly expanded third edition of Numerical Recipes has it, with wider coverage than ever before, many new, expanded and upd......一起来看看 《Numerical Recipes 3rd Edition》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

SHA 加密
SHA 加密

SHA 加密工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换