The following script issues a 'Warning: range() [function.range]: step exceeds the specified range in' only when the date_diff function is called. Does anyone know why?
<?php
$array = array(
"Interno",
"id"
);
$step = count($array) - 1;
foreach (range(开发者_C百科0, $step) as $number) {
echo '<p>'.$number.'</p>';
}
$datetime1 = new DateTime('2010-08-2');
$datetime2 = new DateTime('2009-07-30');
$interval = date_diff($datetime1,$datetime2);
?>
Well, the two functions have nothing to do with each other.
Secondly, the second parameter to range
is not a step, it's a maximum value (see the range
docs... So if you're getting a step exceeds the specified range
error, I'd guess that the default step value 1
is larger than the max of the range (the result of count($array) - 1
)... I'm not sure why that's happening in your code, but it's a start
That's a PHP bug.
Still present as of 5.3.5, it seems that was fixed in 5.3.6.
https://bugs.php.net/bug.php?id=51894
I do agree with ircmaxell, function range and date_diff are not related and do not interact in any way. The issue should be in your array which get altered in some way. Also, as for me, your example contain unnecessary operations like count and range and it could be shortened to this:
<?php
$array = array(
"Interno",
"id"
);
foreach ($array as $number => $value) {
echo '<p>'.$number.'</p>';
}
$datetime1 = new DateTime('2010-08-2');
$datetime2 = new DateTime('2009-07-30');
$interval = date_diff($datetime1,$datetime2);
?>
精彩评论