I'm diddlying with a script, and found some behavior I don't understand.
Take this snippet:
for ($i = 0; $i <= count($m); $i++) {
array_shift($m[$i]);
reset($m);
}
This doesn't work, it says:
Warning: array_shift(): The argument should be an array in ./tool.php on
line 31
However, this does work:
$c = count($m);
for ($i = 0; $i <= $c; $i++) {
array_shift($m[$i]);
}
Why can't I reference the count of $m in the for without it crapping out,
but if I make a variable it is fine? $m doesn't change, so even if it
recounted $m each time, it would be the same.. I'd think.
Many thanks.
--Brian
Take this snippet:
for ($i = 0; $i <= count($m); $i++) {
array_shift($m[$i]);
reset($m);
}
This doesn't work, it says:
Warning: array_shift(): The argument should be an array in ./tool.php on
line 31
However, this does work:
$c = count($m);
for ($i = 0; $i <= $c; $i++) {
array_shift($m[$i]);
}
Why can't I reference the count of $m in the for without it crapping out,
but if I make a variable it is fine? $m doesn't change, so even if it
recounted $m each time, it would be the same.. I'd think.
Many thanks.
--Brian
Comment