|
Posted by Toby Inkster on 03/08/06 10:43
David Haynes wrote:
> Iteration by indexing works and is, as I said, brute force.
Iteration by indexing works *iff* all your indexes are numeric and
sequential. Your for-loop won't work on non-sequential arrays like this:
array(
0 => '123,45',
1 => '123,45',
9 => '123,45'
);
because count() will return 3, meaning that the last element of the array,
with index 9, won't be touched. Nor will it work on:
array(
-1 => '123,45',
0 => '123,45',
1 => '123,45'
);
as your for-loop has a hard-coded start value of 0. Nor will it work on:
array(
'a' => '123,45',
'b' => '123,45',
'c' => '123,45'
);
because the keys aren't numeric. Iván's foreach-loop will work on all of
these three examples.
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
[Back to original message]
|