title: Using simple foreach loop instead of foreach with key=>value in Yii2
body: <p>I have written this code with Yii2 a long time ago to fetch photos for a slideshow and then choose another image size among several images and although it works, as I haven't been working with PHP recently, I don't understand why. I think I should be able to use a simple foreach loop, but when I change it to a simple one, it doesn't work.
  This is the code:</p>
  <pre><code>public static function getSlideShowPage($type)
  {
      $slideShow=SlideShow::find()
          -&gt;select(['title','image','title_position','subtitle', 'title_color'])
          -&gt;where(['deleted' =&gt; 0,'active'=&gt;1,'type'=&gt;$type])
          -&gt;orderBy('id ASC')
          -&gt;groupBy('id')
          -&gt;asArray()
          -&gt;all();
      if(!empty($slideShow))
      foreach ($slideShow as $key=&gt;$slide){
          $slideShow[$key]['image']=str_replace('_xs', &quot;&quot;, $slide['image']);
      }
      return $slideShow;
  }
  </code></pre>
  <p>and what I'm having a problem with is this part:</p>
  <pre><code>    if(!empty($slideShow))
      foreach ($slideShow as $key=&gt;$slide){
          $slideShow[$key]['image']=str_replace('_xs', &quot;&quot;, $slide['image']);
      }
     
  </code></pre>
  <p>Why can't I write it like this:</p>
  <pre><code>if(!empty($slideShow))
      foreach ($slideShow as $slide){
          str_replace('_xs', &quot;&quot;, $slide['image']);
      }
  </code></pre>
  <p>In each foreach loop, I choose one of the array elements and replace the URL of the image.
  I would appreciate any help or suggestion.</p>