cenobite321
Member
- Messages
- 77
- Reaction score
- 0
- Points
- 6
Hello everyone,
I've just got an e-mail from a friend telling me how PHP disliked leading zeroes. He attached the following code:
As the comment highlights the second for statement fails and numbers are not displayed like in the first one. I made the following analysis of both numbers:
The outcome was this:
Weird...:nuts:
I've just got an e-mail from a friend telling me how PHP disliked leading zeroes. He attached the following code:
PHP:
<?php
for($i=01;$i<=07;$i++){
print $i;
echo "<br>";
}
for($i=01;$i<=08;$i++){//with 8 or more it fails
print $i;
echo "<br>";
}
?>
As the comment highlights the second for statement fails and numbers are not displayed like in the first one. I made the following analysis of both numbers:
PHP:
$foo = 07;
//print the type of 07
print '07 is a: '.gettype($foo).'<br>';
//print the value of 07
print $foo.'<br>';
//adds 07 plus 1 and prints the result
$foo = $foo +1;
print $foo.'<br>';
$foo = 08;
//print the type of 08
print '08 is a: '.gettype($foo).'<br>';
//print the value of 08
print $foo.'<br>';
//adds 08 plus 1 and prints the result
$foo = $foo +1;
print $foo.'<br>';
The outcome was this:
07 is a: integer
7
8
08 is a: integer
0
1
Weird...:nuts:
Last edited: