AndreF wrote:no foreach is not suitable for what I want to use.
Why not? It allows you to cycle through each element of the array. If you are not sure if the elements are in array key order, do a [man]ksort/man first, e.g.:
ksort($array, SORT_NUMERIC);
foreach($array as $i => $value)
{
echo "$i: $value<br>\n";
}
please tell me my code above is better or the one given by joe_C_nice ?
If you really feel the need to use a for() loop, then:
$t = count($array);
for($i = 0; $i < $t; $i++)
{
echo "$i: {$array[$i]}<br>\n";
}
The main problem with such a for loop though is that nasty things start to happen if for some reason there is any gap in the array index numbering, whereas that is never a problem with the foreach method.