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

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

内容简介:参见英文答案 >我不知道如何谷歌这一个,所以我在这里问.当我宣布一个变量$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


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

查看所有标签

猜你喜欢:

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

Tango with Django

Tango with Django

David Maxwell、Leif Azzopardi / Leanpub / 2016-11-12 / USD 19.00

Tango with Django is a beginner's guide to web development using the Python programming language and the popular Django web framework. The book is written in a clear and friendly style teaching you th......一起来看看 《Tango with Django》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

MD5 加密
MD5 加密

MD5 加密工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具