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


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

查看所有标签

猜你喜欢:

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

Hadoop: The Definitive Guide

Hadoop: The Definitive Guide

Tom White / O'Reilly Media, Inc. / 2009 / 44.99

Apache Hadoop is ideal for organizations with a growing need to store and process massive application datasets. Hadoop: The Definitive Guide is a comprehensive resource for using Hadoop to build relia......一起来看看 《Hadoop: The Definitive Guide》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器