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:PHP Code:<?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>";
}
?>
The outcome was this:PHP Code:$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>';
Weird...:nuts:07 is a: integer
7
8
08 is a: integer
0
1


LinkBack URL
About LinkBacks
Reply With Quote
