title: Difference between "as $key => $value" and "as $value" in PHP foreach
body: <p>I have a database call and I'm trying to figure out what the <code>$key =&gt; $value</code> does in a <code>foreach</code> loop. </p>
  
  <p>The reason I ask is because both these codes output the same thing, so I'm trying to understand why it's written this way. Here's the code:</p>
  
  <p>1)In foreach use <code>$key =&gt; $value</code></p>
  
  <pre><code>foreach($featured as $key =&gt; $value){
    echo $value['name'];
  }
  </code></pre>
  
  <p>this outputs the same as:</p>
  
  <p>2)In foreach use only <code>$value</code></p>
  
  <pre><code>foreach($featured as $value) {
    echo $value['name'];
  }
  </code></pre>
  
  <p><em>So my question is, what is the difference between <code>$key =&gt; $value</code> or just <code>$value</code> in the <code>foreach</code> loop. The array is multidimensional if that makes a difference, I just want to know why to pass <code>$key</code> to <code>$value</code> in the <code>foreach</code> loop.</em></p>