<p>Is it possible to find the <code>foreach</code> index?</p>

<p>in a <code>for</code> loop as follows:</p>

<pre><code>for ($i = 0; $i &lt; 10; ++$i) {
   echo $i . ' ';
}
</code></pre>

<p><code>$i</code> will give you the index.</p>

<p>Do I have to use the <code>for</code> loop or is there some way to get the index in the <code>foreach</code> loop?</p>

```
```
foreach($array as $key=>$value) {
    // do stuff
}
```
```
```
$key
```
is the index of each
```
$array
```
element