I am using the following loop to traverse an array where i need both the value and the key field.
while ($value = current($a)) {
echo "$value ".key($a).'<br />';
next($a);
}
The problem is that the traversal only takes place till a ‘0’ is encountered in the array as the while statement says.Is there any way i can traverse array with zero values(size of array varies) and get both value and key.
just use a foreach-loop:
it’s much simpler and sounds exactly like what you’re looking for.