Take a look at the code below:
Code: Select all
<pre>
<?php
$anyArray = array(
17 => "News",
3 => "Prod. Agroquímicos",
1 => "Prod. Farmaceuticos",
2 => "Prod. Veterniarios");
echo key($anyArray) . " => ";
echo current($anyArray) . "\n";
next($anyArray);
echo key($anyArray) . " => ";
echo current($anyArray) . "\n";
echo reset($anyArray) . " (reseting the pointer to first element)\n";
echo key($anyArray) . " => ";
echo current($anyArray) . "\n";
?>
</pre>
The above code's output:
Code: Select all
17 => News
3 => Prod. Agroquímicos
News (reseting the pointer to first element)
17 => News
The
reset() function you already know.
key() returns the index of the current array element, which is returned by
current(). And
next() advance the internal array pointer to the next element.
I suggest you take a careful look at the Array Functions chapter of the PHP Manual located at
http://www.php.net/manual/en/ref.array.php. There you'll find a detailed documentation covering php array functions.
Regards,
Scorphus.