note 99161 rejected from function.intval by danbrown
| From: | danbrown@php.net | Date: | Sun, 01 Aug 2010 14:07:17 +0000 |
| Subject: | note 99161 rejected from function.intval by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-171316@lists.php.net to get a copy of this message | ||
Note Submitter: ricardo dot massaro at gmail dot com
----
This documentation is misleading. The actual default value for the $base parameter is 0, not 10.
When you pass $base=0 (or don't specify it), the function will "guess" the base from
the contents of the given string, emulating C: if the string starts with "0x", the used
base will be 16, if the string starts with "0", the used base will be 8, otherwise the
used base will be 10.
So, pass $base=10 explicitly if you want to force any leading zeroes to be ignored (and prevent them
from triggering base 8).
Examples:
<?php
intval("010"); // 8
intval("010", 0); // 8
intval("010", 10); // 10
?>