I have to iterate over an array and I can't decide which is the 'better' way. Theres a few different constructs that allow for this. Firstly... I can do something simple like..
while($row = current($arr)) {
$row["my_col"];
next($arr);
}
which stops if $row is 0 or "0" i believe.
next is the list, each methods...
while(list($key, $val) = each($arr)) {
echo "$key is $val";
}
finally, in PHP4 .. there is the foreach construct...
foreach($arr as $key => $val) {
echo "$key is $val";
}
I realize this is pretty much the same as using list / each... but is there perhaps a reason to choose one over the other? manual says foreach uses a copy of the array (but i'm assuming the while list/each does the same)..[althought I'm a little unsure about the foreach looping each entry twice.. one for numeric index and one for associative index]
Is there a more accepted practice?